HTTPS API上的发布会收到空响应。在使用HTTP之前一切正常。但上周,当第三方公司将链接更改为HTTPS时,一切都发生了变化。我没有收到使用HTTP收到的实际消息。我对它做了一些研究,我发现php curl无法读取安全连接???我让第三方公司提供他们在HTTPS中的证书,以便我可以将它包含在我的工作源代码(下面)中,并测试我是否可以收到任何响应,但我失败了!这是我的源代码,如下所示。有人可以帮我吗?感谢
更新包含标题
$headers = array(
// "Accept-Encoding: gzip, deflate",
"Content-Type: text/xml;charset=\"UTF-8\"",
"SOAPAction: \"http://tempuri.org/IAppMain/Post\"",
"Connection: Keep-Alive",
"Content-length: ".strlen($xml_post_string),
);
$soap_do = curl_init();
set_time_limit(0);
curl_setopt($soap_do, CURLOPT_URL, $url);
curl_setopt($soap_do, CURLOPT_AUTOREFERER, true);
curl_setopt($soap_do, CURLOPT_MAXREDIRS, 10);
curl_setopt($soap_do, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($soap_do, CURLOPT_CAINFO, APPPATH . "/RSA/BC/sslcertificateof.pem");
curl_setopt($soap_do, CURLOPT_POST, true );
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $xml_post_string);
curl_setopt($soap_do, CURLOPT_VERBOSE, TRUE);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $headers);
curl_setopt($soap_do, CURLOPT_HEADER, false);
// Converting
$response = curl_exec($soap_do);
$error = curl_error($soap_do);
if(curl_errno($soap_do))
{
echo "Curl Failed: " . curl_errno($soap_do), "<br/>";
echo curl_error($soap_do);
} else {
$dom = new DOMDocument();
$dom->loadXML($response); // Suppose if there's no error I will see an XML, but I get empty string.
}
答案 0 :(得分:0)
您可以尝试将其添加到php.ini
curl.cainfo=c:\path\to\cacert.pem
并设置curl_setopt_array
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_SSL_VERIFYPEER => false // Disabled SSL Cert checks
);
curl_setopt_array( $soap_do, $options );
将你的结果发表评论。
答案 1 :(得分:0)
尝试将CURLOPT_SSL_VERIFYPEER更改为0
同时尝试将CURLOPT_FOLLOWLOCATION设置为FALSE,这样您就可以100%确定您正在调试的连接过程的哪个部分。
最后:使用像Fiddler这样的工具来监控流量