简体   繁体   English

空字符串响应curl PHP在https发布

[英]Empty string response curl php on https posting

Posting on HTTPS API receives empty response. 在HTTPS API上发布收到空响应。 Before when using HTTP everything worked fine. 在使用HTTP之前,一切正常。 But last week when 3rd party company changed the link to HTTPS everything has changed. 但是上周,当第三方公司将链接更改为HTTPS时,一切都变了。 I didn't receive the actual message I receives using HTTP. 我没有收到使用HTTP收到的实际消息。 I made some research about it and I find out that php curl doesn't able to read the secured connection??? 我对此进行了一些研究,发现php curl无法读取安全连接??? I asked the 3rd party company to provide the certificate they have in HTTPS so that I can include it on my working source code (Below) and test if I can receive any response, but I failed!!!! 我请第三方公司提供他们在HTTPS中拥有的证书,以便我可以将其包括在工作源代码中(如下),并测试是否可以收到任何响应,但是失败了! Here's my source code below. 这是我下面的源代码。 can someone help me about it? 有人可以帮我吗? thanks 谢谢

UPDATE Include the header 更新包括标题

$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.
}

You can try add it to php.ini 您可以尝试将其添加到php.ini

curl.cainfo=c:\path\to\cacert.pem

And setup curl_setopt_array 并设置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 );

Give me your result in comment. 在评论中给我您的结果。

Try changing CURLOPT_SSL_VERIFYPEER to 0 尝试将CURLOPT_SSL_VERIFYPEER更改为0
And at the same time try initially setting CURLOPT_FOLLOWLOCATION to FALSE, so you can be 100% sure that you what part of the connect-process you are debugging. 同时,尝试将CURLOPT_FOLLOWLOCATION初始设置为FALSE,这样就可以100%确定要调试的连接过程的哪一部分。
And finaly: use a tool like Fiddler to monitor the traffic 最后:使用Fiddler之类的工具来监控流量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM