2016-01-21 192 views
1

我有一個cURL請求在通過我的PHP 5.4.48應用運行時失敗。有趣的是,它直接通過控制檯或Postman運行時正確執行。cURL不受支持的SSL協議

我連接的API需要TLSv1.2連接,我在我的應用程序中指定了它。

這裏是我的簡單的要求,因爲它是在我的PHP應用程序:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://dev-dataconnect.givex.com:50104'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$payload); 

curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain;charset=UTF-8')); 
curl_setopt($ch, CURLOPT_SSLVERSION, 6); 
// curl_setopt($ch, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_TLSv1_2'); // specifying value by name was of no help 
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLS_RSA_WITH_AES_256_CBC_SHA256'); 

curl_exec($ch); 

原始捲曲的要求是這樣的(注意,這從成功打響控制檯內)

curl 'https://dev-dataconnect.givex.com:50104/' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36' -H 'Content-Type: text/plain;charset=UTF-8' -H 'Accept: */*' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' --data-binary $'{"method":"dc_909","id":"confidential","jsonrpc":"2.0","params":["en","confidential","29530","confidential"]}\n' --compressed 

還要注意我並不需要指定SSL版本以進行成功的握手

以下是運行curl的打印輸出-v'https://dev-dataconnect.givex.com:50104/'

* Connected to dev-dataconnect.givex.com (72.15.49.106) port 50104 (#0) 
* TLS 1.2 connection using TLS_RSA_WITH_AES_256_CBC_SHA256 
* Server certificate: *.givex.com 
* Server certificate: Trustwave Organization Validation SHA256 CA, Level 1 
* Server certificate: SecureTrust CA 
> GET/HTTP/1.1 
> Host: dev-dataconnect.givex.com:50104 
> User-Agent: curl/7.43.0 
> Accept: */* 

我跑

- PHP 5.4.48 
- curl 7.43.0 (within both my MAMP and my Mac environments) 
- OpenSSL/0.9.8zd (within both my MAMP and my Mac environments) 

我一直在排除故障自上週以來這個問題。有任何想法嗎???

+1

是類似的問題? http://stackoverflow.com/questions/21612132/unsupported-protocol-using-curl-in-c –

+0

感謝但不是相同的問題。該海報試圖在沒有支持HTTPS的cURL安裝的情況下發出HTTPS cURL請求。 –

+0

預期結果是什麼? –

回答

2
  • 的OpenSSL/0.9.8zd(我的兩個MAMP內和我的Mac環境)

...

我連接到該API需要一個TLSv1.2工作連接,我在我的應用程序中指定。

OpenSSL 0.9.8不支持TLS 1.2。僅在OpenSSL 1.0.1中添加了支持。

+0

你是如何解決這個問題的?同樣的問題我要去' – Rajesh

0

下面的代碼對我的作品:

<?php 
$curl = curl_init(); 

curl_setopt_array($curl, array(
    CURLOPT_PORT => "50104", 
    CURLOPT_URL => "https://dev-dataconnect.givex.com:50104/", 
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_ENCODING => "", 
    CURLOPT_MAXREDIRS => 10, 
    CURLOPT_TIMEOUT => 30, 
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 
    CURLOPT_CUSTOMREQUEST => "POST", 
    CURLOPT_POSTFIELDS => "{\"method\":\"dc_909\",\"id\":\"confidential\",\"jsonrpc\":\"2.0\",\"params\":[\"en\",\"confidential\",\"29530\",\"confidential\"]}", 
    CURLOPT_HTTPHEADER => array(
    "accept: */*", 
    "accept-encoding: gzip, deflate", 
    "accept-language: en-US,en;q=0.8", 
    "cache-control: no-cache", 
    "connection: keep-alive", 
    "content-type: text/plain;charset=UTF-8", 
    "user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36" 
), 
)); 

$response = curl_exec($curl); 
$err = curl_error($curl); 

curl_close($curl); 

if ($err) { 
    echo "cURL Error #:" . $err; 
} else { 
    echo $response; 
} 
?> 
+0

這使用版本1。1,而不是問題中指定的1.2。 – carbide20

0

步驟1:打開你的phpinfo()

第2步:轉到cUrl部分

3步:檢查SSL被啓用。如果不是,您將面臨Unsupported SSL Protocol錯誤。

解決方案:

嘗試啓用SSL在你的MAMP或安裝最新版本MAMP的

enter image description here