我有一个使用cURL(最新版本)连接到安全网关进行支付的站点.
问题是cURL总是返回0长度的内容.我只收到标题.只有当我设置cURL返回标题时.我有以下标志.
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $gatewayURI);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POST, 1);
Run Code Online (Sandbox Code Playgroud)
返回的标头是
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Tue, 25 Nov 2008 01:08:34 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Length: 0
Content-Type: text/html
Set-Cookie: ASPSESSIONIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx; path=/
Cache-control: private
Run Code Online (Sandbox Code Playgroud)
我也试过cURL'ing不同的网站,他们返回内容很好.我认为这个问题可能与https连接有关.
我和公司谈过,他们没有帮助.
有没有其他人遇到过这个错误并知道解决方法?我应该抛弃cURL并尝试使用fsockopen()?
谢谢.:)
Sch*_*kie 99
我今天遇到了同样的问题.Curl附带了一个过时的文件来验证来自的HTTPS证书.
得到新的:
http://curl.haxx.se/ca/cacert.pem
将其保存到您网站上的某个目录中
并添加
curl_setopt ($curl_ch, CURLOPT_CAINFO, dirname(__FILE__)."/cacert.pem");
Run Code Online (Sandbox Code Playgroud)
对每一个要求:-)
IGNORE关于禁用CURLOPT_VERIFYPEER和CURLOPT_VERIFYHOST的任何愚蠢的评论!! 这使得你的代码在中间攻击中容易受到攻击!
2016年12月编辑:
使用下面提到的Jasen方法正确解决这个问题.
加curl.cainfo=/etc/ssl/certs/ca-certificates.crt你php.ini
2017年10月编辑:
现在有一个composer包可以帮助您管理ca证书,这样如果您的cacert.pem由于撤销证书而变得过时,您就不会受到攻击.
https://github.com/paragonie/certainty - >composer require paragonie/certainty:dev-master
mix*_*dev 28
注意:这绝对不是生产用途.如果您想快速调试,这可能很有用.否则,请使用@ SchizoDuckie的答案.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
Run Code Online (Sandbox Code Playgroud)
只需添加它们.有用.
只是有一个非常相似的问题,并通过添加解决它
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
Run Code Online (Sandbox Code Playgroud)
显然我正在抓取的网站重定向到另一个位置,并且php-curl默认不遵循重定向.