dregduc63699 2013-09-02 11:47
浏览 57
已采纳

PHP和XML - 如何使用此XML在PHP中生成soap请求?

I am completly new to SOAP operations.

I have been provided with an XML document (SOAP) to get some collection points for a shipping method.

From the manual located here:

http://privpakservices.schenker.nu/package/package_1.3/packageservices.asmx?op=SearchCollectionPoint

I can see that I need to use the following SOAP request:

POST /package/package_1.3/packageservices.asmx HTTP/1.1
Host: privpakservices.schenker.nu
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://privpakservices.schenker.nu/SearchCollectionPoint"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SearchCollectionPoint xmlns="http://privpakservices.schenker.nu/">
      <customerID>long</customerID>
      <key>string</key>
      <serviceID>string</serviceID>
      <paramID>int</paramID>
      <address>string</address>
      <postcode>string</postcode>
      <city>string</city>
      <maxhits>int</maxhits>
    </SearchCollectionPoint>
  </soap:Body>
</soap:Envelope>

The thing is that i don't know how to send this as a request using PHP, and how to get the response.

Any help to pinpoint me in the right direction, is much appreciated.

UPDATE

I can read the response data with var_dump. However, I am not able to read individual element data.

I need to read data as below

foreach($parser as $row) {
  echo $row->customerID;
  echo $row->key;
  echo $row->serviceID;  
}
  • 写回答

2条回答 默认 最新

  • dsstlsqt696435 2013-09-02 20:35
    关注

    If anyone should be interested, i have provided the correct answer:

    $soapUrl = "http://privpakservices.schenker.nu/package/package_1.3/packageservices.asmx?op=SearchCollectionPoint";
    
    $xml_post_string = '<?xml version="1.0" encoding="utf-8"?><soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:Body><SearchCollectionPoint xmlns="http://privpakservices.schenker.nu/"><customerID>XXX</customerID><key>XXXXXX-XXXXXX</key><serviceID></serviceID><paramID>0</paramID><address>RiksvŠgen 5</address><postcode>59018</postcode><city>Mantorp</city><maxhits>10</maxhits></SearchCollectionPoint></soap12:Body></soap12:Envelope>';
    
    $headers = array(
    "POST /package/package_1.3/packageservices.asmx HTTP/1.1",
    "Host: privpakservices.schenker.nu",
    "Content-Type: application/soap+xml; charset=utf-8",
    "Content-Length: ".strlen($xml_post_string)
    ); 
    
    $url = $soapUrl;
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    $response = curl_exec($ch); 
    curl_close($ch);
    
    $response1 = str_replace("<soap:Body>","",$response);
    $response2 = str_replace("</soap:Body>","",$response1);
    
    $parser = simplexml_load_string($response2);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.