使用CURL将发布请求发送到SSL认证域

时间:2018-12-06 11:35:56

标签: php curl

我需要使用POST从一台(windows)服务器发送到另一台(Linux)服务器CURL请求,接收者域具有SSl证书。

我的代码:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://receiver_url");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("a"=>"aaa"));
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_CAINFO, "C:/wamp64/cacert.pem");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
echo curl_errno($ch);
curl_close ($ch);

errno显示0,但请求未发送,我在做什么错了?

1 个答案:

答案 0 :(得分:0)

一个快速(又肮脏)的解决方法是编辑以下行:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

它将cURL配置为接受任何服务器(对等)证书。

您可以找到更整洁的修复程序以及有关问题here的更多信息。