【问题标题】:Curl Error "HTTP error before end of send, stop sending" when sending SOAP request php发送 SOAP 请求 php 时出现卷曲错误“发送结束前的 HTTP 错误,停止发送”
【发布时间】:2015-09-09 16:42:38
【问题描述】:

所以我需要与 SOAP API 交互,我通过 curl 使用以下函数发送我的肥皂消息

    /**
     * @param $soap_msg
     * @return int
     */
    function send($soap_msg)
    {

        //init curl
        $ch = curl_init();

        //set some debug
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_HEADER, true);

        //set request method
        curl_setopt($ch, CURLOPT_POST, true);

        //set some other options
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, true);
        curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);

        //set auth info
        $username = 'user';
        $password = '%PASS$';
        curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);

        //build header array
        $headers = array();
        $headers[] = 'Content-Type: application/soap+xml; charset=utf-8';
        $headers[] = 'Accept-Encoding: gzip, deflate';
       $headers[] = 'Connection: Keep-Alive';
        $headers[] = 'Expect: 100-continue';
        $headers[] = 'SOAPAction: http://ACTION/URL';
        $headers[] = "Content-length: ".strlen($soap_msg);

        //set headers
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        //set payload
        curl_setopt($ch, CURLOPT_POSTFIELDS, $soap_msg);

        //set soap resource
        curl_setopt($ch, CURLOPT_URL, 'https://SOME.URL.co.uk/SERVICE.svc/detail');

        //execute request
        curl_exec($ch);

        $info = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        curl_close($ch);

        return $info;
    }

    echo send($soap_msg);
?>

传递的 SOAP 消息

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://my.action/endpoint/GetJob</a:Action>
    <a:MessageID>urn:uuid:b7747707-97cc-4edf-9cb0-b8dd40f45509</a:MessageID>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <a:To s:mustUnderstand="1">https://my.webservice.co.uk/Appt/AppointWS/service.svc/detail</a:To>
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <u:Timestamp u:Id="_0">
        <u:Created>2015-09-08T19:52:16.065Z</u:Created>
        <u:Expires>2015-09-08T19:57:16.065Z</u:Expires>
      </u:Timestamp>
      <o:UsernameToken u:Id="uuid-2c7e3d75-b18d-480a-979e-57e6a042e9f2-2">
        <o:Username>user</o:Username>
        <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">%pass$</o:Password>
      </o:UsernameToken>
    </o:Security>
  </s:Header>
  <s:Body>
    <GetJob xmlns="http://tempuri.org/">
      <jobEntryId>630422258</jobEntryId>
      <jobNo1>3874527</jobNo1>
      <contractId>220000</contractId>
    </GetJob>
  </s:Body>
</s:Envelope>

回显输出给出 500 错误

我从上周为另一个运行良好的 SOAP 服务编写的函数中剥离了该函数的基础知识,所以我对问题所在感到有些困惑

编辑: 刚刚在 mac 'Restinsoap' 上的外部客户端中尝试过这个,我得到以下响应仍然是 500

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action>
    <a:RelatesTo>urn:uuid:588e5592-c60a-4c2d-b643-c6af9c4772f5</a:RelatesTo>
  </s:Header>
  <s:Body>
    <s:Fault>
      <s:Code>
        <s:Value>s:Sender</s:Value>
        <s:Subcode>
          <s:Value xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">a:InvalidSecurity</s:Value>
        </s:Subcode>
      </s:Code>
      <s:Reason>
        <s:Text xml:lang="en-GB">An error occurred when verifying security for the message.</s:Text>
      </s:Reason>
    </s:Fault>
  </s:Body>
</s:Envelope>

但是如果我在 Windows 机器上的 wcfstorm 中执行请求就可以了

【问题讨论】:

    标签: php web-services iis curl soap


    【解决方案1】:

    SOAP 服务需要在有效负载的标头部分中提供身份验证详细信息。

    尝试在 RestInSoap 客户端中负载的标头部分 (&lt;x:Header&gt;?&lt;/x:Header&gt;) 中添加此 WSS 令牌。

    根据需要更改用户名和密码。

    <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
         <wsse:UsernameToken wsu:Id="UsernameToken-1">
            <wsse:Username>asd</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">asd</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">8lrPhyvoNtE8Gp0wOJMcOw==</wsse:Nonce>
            <wsu:Created>2015-09-10T05:17:40.296Z</wsu:Created>
         </wsse:UsernameToken>
     </wsse:Security>
    

    【讨论】:

    • 是的,我没有包含我发送的 SOAP 消息,但我们发送了带有这些详细信息的完全格式化的 SOAP 消息。如前所述,我可以从基于 Windows 的 SOAP 客户端发送,但是当 php 出现错误时
    • 我在原始问题中添加了发送的信封
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-06
    • 2013-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多