【问题标题】:how to send SOAP request in curl如何在 curl 中发送 SOAP 请求
【发布时间】:2013-07-01 22:06:45
【问题描述】:

我是肥皂的初学者,我如何发送肥皂请求?我在谷歌搜索并尝试了不同的方法,但遗憾的是它对我没有用。

非常感谢您的帮助。

这是我应该发送的示例请求:

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>

【问题讨论】:

  • 我对@9​​87654324@ 的主要建议是不要放弃它![抱歉,忍不住来喷 :)。]
  • SOAP request in PHP with CURL 的可能副本 - 和其他一些。请在提问前使用搜索。
  • @hakre likes 放弃SOAP
  • 然后像在冰上溜冰一样滑过浴室。

标签: php xml soap curl


【解决方案1】:

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();
}

【讨论】:

  • 我收到此错误 McCode : SOAP-ERROR: Parsing WSDL: Couldn't load from
  • 你更新代码中的wsdl了吗?在浏览器中检查它是否可以访问。
  • 我不知道如何检查它是否可以访问 MrCode。我对肥皂或wsdl没有经验,我只是自学。感谢您的帮助
  • 尝试在浏览器中查看 WSDL 链接,就像网页一样。这应该让您知道它是否可以访问。示例 sample.com/Universal/WebService.asmx?wsdl(将 sample.com 更改为您的)
  • 是的,但您是否通过尝试导航到浏览器对其进行了测试?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多