php - cURL 不支持的 SSL 协议(protocol)

标签 php ssl curl tls1.2

我有一个 cURL 请求在通过我的 PHP 5.4.48 应用程序运行时失败了。有趣的是,当直接通过控制台或通过 Postman 运行它时,它会正确执行。

我正在连接的 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 请求看起来像这样(注意它从控制台中成功触发)

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)

自上周以来,我一直在解决这个问题。有什么想法吗???

最佳答案

  • OpenSSL/0.9.8zd (within both my MAMP and my Mac environments)

...

The API I'm connecting to expects a TLSv1.2 connection, which I am specifying in my app.

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

关于php - cURL 不支持的 SSL 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34914065/

相关文章:

curl - Python 请求 SSL 认证问题(和 curl)

php - 如何在 Laravel 5 中使用我自己的 Jquery

email - 使用您的 GMail 帐户作为 SMTP 服务器从 App 发送电子邮件

php - 在 Enterprise Architect 中为 PHP 生成 getters 和 setters

c# - 了解通过 SSL 进行调用的代码

ssl - 如何在 Gunicorn 中禁用 SSLv3.0 并使用 TLS1.0

bash - 如何为 curl 命令对数据进行 urlencode?

PHP: UTF 8字符编码

php - Magento 1.8重新索引所有

php - 如何从构造函数中正确提取“类型” mysqli