使用PHP消费SOAP服务

时间:2016-12-02 11:57:48

标签: php xml soap

我尝试使用PHP来使用SOAP服务。我更喜欢使用cURL,但PHP-SOAP也是一种选择。

我有一个例子:

端点:https://devpoints.ex.com:8443/UserSystem.svc/basic

接头:

POST /UserSystem.svc/basic HTTP/1.1
Host: devpoints.ex.com:8443
Content-Type: text/xml; charset=utf-8
Authorization: Basic OWRWXHVhdGpkc3BvcnRzKmFXakNrOUNYNTg4bzRZakFSePWq
SOAPAction: http://tempuri.org/IUserSystemInterface/GetCurrentPointConfiguration
Accept-Encoding: gzip, deflate

XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:cph="http://schemas.datacontract.org/2004/07/Dev.UserBank.WebServices">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:GetCurrentPointConfiguration>
         <tem:header>
           <cph:SystemInstance>myshopname</cph:SystemInstance>
         </tem:header>
      </tem:GetCurrentPointConfiguration>
   </soapenv:Body>
</soapenv:Envelope>

从上面我尝试了以下内容,它返回202:

$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:cph="http://schemas.datacontract.org/2004/07/Dev.UserBank.WebServices">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:GetCurrentPointConfiguration>
         <tem:header>
           <cph:SystemInstance>myshop</cph:SystemInstance>
         </tem:header>
      </tem:GetCurrentPointConfiguration>
   </soapenv:Body>
</soapenv:Envelope>';


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://devpoints.ex.com:8443/UserSystem.svc/basic');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  'POST /UserSystem.svc/basic HTTP/1.1',
  'Host: devpoints.ex.com:8443',
  'Content-Type: text/xml; charset=utf-8',
  'Authorization: Basic OWRWXHVhdGpkc3BvcnRzKmFXakNrOUNYNTg4bzRZakFSePWq',
  'SOAPAction: http://tempuri.org/IUserSystemInterface/GetCurrentPointConfiguration',
  'Accept-Encoding: gzip, deflate',
  'Content-Length: ' . strlen( $xml ),
));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);

$resp = curl_exec($ch);

所以......任何想法,因为我得到了202,我做错了什么?

0 个答案:

没有答案