Curl SOAP POST请求PHP 5.5.9

时间:2017-03-03 21:59:00

标签: php curl soap

我希望有经验的人可以使用Curl和PHP来帮助我。我有从我的PHP应用程序向远程服务器发出SOAP PHP请求的情况,该服务器从我的本地服务器运行良好(PHP 7.0,Curl 7.47) 问题是当我使用PHP 5.5.9和curl 7.50在我的服务器上部署应用程序时,代码完全相同,我从Curl调用得到空响应。以下是代码的一部分:

$xml_post_string  = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tcit="urn:microsoft-dynamics-schemas/page/tcitems">';
        $xml_post_string .=     '<soapenv:Header/>';
        $xml_post_string .=     '<soapenv:Body>';
        $xml_post_string .=         '<tcit:ReadMultiple>';
        $xml_post_string .=         '</tcit:ReadMultiple>';
        $xml_post_string .=     '</soapenv:Body>';
        $xml_post_string .= '</soapenv:Envelope>'; 

   $headers = array(
        "Content-type: text/xml;charset=\"utf-8\"",
        "Accept: text/xml",
        "Cache-Control: no-cache",
        "Pragma: no-cache",
        "SOAPAction: `here goes my remote url which I am calling`"
    );


    // PHP cURL  for https connection with auth
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password - declared at the top of the doc
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($ch, CURLOPT_TIMEOUT, 300);
    curl_setopt($ch, CURLOPT_VERBOSE, true);

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

实际上我得到空字符串作为响应,但是当我调试时,我看到问题是401请求(与auth有什么关系?)。无论如何,脚本在我的本地主机上工作得很好,所以我认为它与远程服务器上的某些版本不兼容性有关。让我听听您的想法,您认为这种配置可能是什么问题。

$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); (this return 401)
$curl_errno= curl_errno($ch); (this returns 0)

0 个答案:

没有答案