Curl 请求在 SSL 上失败?
我有这段代码
if(ereg("^(https)",$url))
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
// execute, and log the result to curl_put.log
$result = curl_exec($curl);
$error = curl_error($curl);
指定的错误是
SSL read: error:00000000:lib(0):func(0):reason(0), errno 104
任何关于原因的想法
I have this code
if(ereg("^(https)",$url))
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
// execute, and log the result to curl_put.log
$result = curl_exec($curl);
$error = curl_error($curl);
The error specified is
SSL read: error:00000000:lib(0):func(0):reason(0), errno 104
Any ideas on the cause
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我在使用第三方库时遇到了类似的神秘错误。我尝试了
CURLOPT_SSL_VERIFY[PEER|HOST]
但没有什么区别。我的错误消息类似:所以我访问了 http://curl.haxx.se/ libcurl/c/libcurl-errors.html,查找错误代码 54。
不过这是错误的 - 我在应用程序的其他部分使用curl 发出其他 HTTPS 请求。所以我继续挖掘并发现了这个问题,R & RCurl:libcurl 中出现错误 54,其中包含以下 gem:
因此,不要让 curl_error() 的输出误导您。相反,使用 curl_errno() 来获取正确的
I encountered a similar cryptic error while working with a third-party library. I tried the
CURLOPT_SSL_VERIFY[PEER|HOST]
but it made no difference. My error message was similar:So I visited http://curl.haxx.se/libcurl/c/libcurl-errors.html, looking for the error code 54.
This was wrong though - I was making other HTTPS requests using curl in other parts of the application. So I kept digging and found this question, R & RCurl: Error 54 in libcurl, which had this gem:
So, don't let the output of curl_error() mislead you. Instead, use curl_errno() to obtain the correct error code, which in this case was actually 56, CURLE_RECV_ERROR. Had the wrong host name...
使用 SSL,请确保您已从 php.ini 打开openssl 扩展。
With SSL, make sure that you have openssl extension turned on from php.ini.
我也遇到过同样的问题。事实证明,目标系统上的 ssl 配置有问题。
检查了 php curl 模块、GuzzleHttp 版本、openssl 版本后,我在浏览器中调用了该链接,它起作用了。但是使用
curl --tlsv1 -kv https://www.example.com
控制台仍然有错误。所以我在 https://www.ssllabs.com/ssltest/ 检查了 ssl 配置,它被评为与 B. 还有一些我以前从未见过的在线证书状态协议 (OCSP) 错误。最后,我将目标系统上的配置更改为 https://cipherli.st/ 中的建议,重新启动了网络服务器和所有内容工作了。 ssllabs 的新评级现为 A+。
我的 nginx 配置(Ubuntu 14.04,nginx 1.4.6-1ubuntu3.5):
I've had the same problem. It turned out, that the ssl on the target system had a bad configuration.
After checking the php curl module, the GuzzleHttp version, the openssl version I called the link in the browser and it worked. But with
curl --tlsv1 -kv https://www.example.com
on the console there was still an error.So I checked the ssl configuration at https://www.ssllabs.com/ssltest/ It was rated with B. And there where some Online Certificate Status Protocol (OCSP) errors I haven't seen before. Finally I changed my configuration on the target system to the suggestions at https://cipherli.st/ restarted the webserver and everything worked. The new rating at ssllabs is now A+.
My nginx configuration (Ubuntu 14.04, nginx 1.4.6-1ubuntu3.5):
我认为你的意思是使用 CURLOPT_SSL_VERIFYHOST,而不是 CURLOPT_SSL_VERIFYPEER
I think you mean to use CURLOPT_SSL_VERIFYHOST, not CURLOPT_SSL_VERIFYPEER
添加这个:
我有同样的错误并且对我来说工作得很好。
add this:
I had the same error and worked fine for me.
我的函数
curl_error
打印了相同的错误,但这不一定与 SSL 有关。最好使用函数curl_errno
打印精确的错误号,这样您就可以从那里更好地诊断。就我而言,它返回了 52 错误代码,我可以从那里进行调试,事实上另一台服务器没有发送任何数据。I had the same error printed by the function
curl_error
but this is not necessarily related to SSL. It is better to print the precise error number with the functioncurl_errno
and you can diagnose better from there. In my case it returned me a 52 error code and I could debug from there, in fact the other server was not sending any data.这意味着目标服务器需要 SSL 通信。
您应该为您运行 CURL 请求的发送服务器生成 SSL 证书
Let's Encrypt 是第一个免费且开放的 CA
此处描述了所有内容 sslforfree.com
It means the destination server require an SSL communication.
You should generate an SSL certificate for your sending server from wich you run the CURL request
Let's Encrypt is the first free and open CA
Everything is described here sslforfree.com
我解决了这个curl错误:“SSL read: error:00000000:lib(0):func(0):reason(0), errno 104”,方法是从我的url查询参数值(逗号分隔值)中删除额外的空格。
例如:
https://example.com?a=123,456,SPACE_ADDED_BY_MISTAKE789
到
https://example.com?a=123,456,789
I solved this curl error: "SSL read: error:00000000:lib(0):func(0):reason(0), errno 104" by removing extra space from my url query parameter value (comma separated values).
For example:
https://example.com?a=123,456,SPACE_ADDED_BY_MISTAKE789
to
https://example.com?a=123,456,789