2013-07-04 173 views
4

我是肥皂的初学者,我如何发送soap请求?我在谷歌搜索和尝试不同的方法,但可悲的是它没有为我工作。如何发送curl中的SOAP请求

我真的很感谢你的帮助。

这里,我应该送样要求:

POST /Universal/WebService.asmx HTTP/1.1 
Host: www.sample.com 
Content-Type: text/xml;charset="utf-8" 
Content-Length: length 
SOAPAction: https://www.sample.com/Universal/WebService.asmx/Request 

<?xml version=\"1.0\" encoding=\"utf-8\"?> 
<soap:Envelope xmlns:xsi="http://wwww.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
<soap:Body> 
<Request xmlns="https://www.sample.com/Universal/WebService.asmx"> 
<ID>CPHK01</ID> 
<UID>TEST</UID> 
<PWD>TEST</PWD> 
<target_mpn>09183530925</target_mpn> 
<amount>115</amount> 
<ref_no>20060830143030112</ref_no> 
<source_mpn>67720014</source_mpn> 
</Request> 
</soap:Body> 
</soap:Envelope> 

这里的响应:

HTTP/1.1 200 OK 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 

<?xml version = "1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://wwww.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
<soap:Body> 
<RequestResponse xmlns="https://www.sample.com/Universal/WebService.asmx"> 
<RequestResult> 
<Ref_no>20060830143030112</Ref_no> 
<StatusCode>101</StatusCode> 
</RequestResult> 
</RequestResponse> 
</soap:Body> 
</soap:Envelope> 
+3

我对'SOAP'的主要建议是**不要丢弃!**。 * [抱歉,无法阻止拖动:)。] * – CodeAngry

+0

[PHP的CURL中的SOAP请求]的可能重复(http://stackoverflow.com/questions/7120586/soap-request-in-php-with-curl ) - 和其他一些。在提问前请使用搜索。 – hakre

+0

@hakre **喜欢**放弃'SOAP' – Jimbo

回答

3

PHP提供了一个原生SoapClient类。构造函数将WSDL作为参数。这比cURL更受欢迎,因为SoapClient处理所有的SOAP错综复杂的问题,它允许您处理本地对象和数组,并且无需手动构建SOAP信封和XML。

try { 
    $client = new SoapClient('https://www.sample.com/Universal/WebService.asmx?wsdl'); 
    $response = $client->Request(array(
     'ID' => 'xxxx', 
     'UID' => 'xxxx', 
     'PWD' => 'xxxx', 
     'target_mpn' => 'xxxx', 
     'amount' => 'xxxx', 
     'ref_no' => 'xxxx', 
     'source_mpn' => 'xxxx' 
    )); 

    print_r($response); // view the full response to see what is returned 

    // or get the response properties: 
    echo $response->RequestResult->Ref_no; 
    echo $response->RequestResult->StatusCode; 

} catch (Exception $e) { 
    echo $e->getMessage(); 
} 
+0

谢谢MrCode我会给你一个这样的镜头。 – lgDroidZ

+0

我收到了这个错误McCode:SOAP-ERROR:解析WSDL:无法从 – lgDroidZ

+0

加载您是否更新了代码中的wsdl?在浏览器中检查它是否可以访问。 – MrCode