首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将XML发送到wsdl端点

如何将XML发送到wsdl端点
EN

Stack Overflow用户
提问于 2020-05-13 16:55:13
回答 1查看 71关注 0票数 0

我希望你们都做得好。在SOAP方面,我不需要什么帮助。我想发送XML,我有WSDL端点。有人能帮我吗,怎么做?我会感谢你的帮助。

首先,什么样的方法是比较好的CURL和soapClient?

这是端点 http://some_ip/some_channel/services/some_service?wsdl

和XML在这里:

代码语言:javascript
复制
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
   <ban:someMthod>
      <chnlNum>somenumber</chnlNum>
      <chnlPasWd>some password</chnlPasWd>
      <userNum>some number</userNum>
      <amount>some amount</amount>
      <requestDate>some date</requestDate>
      <requestId>some random number</requestId>
   </ban:someMethod>
</soapenv:Body>
</soapenv:Envelope>
EN

回答 1

Stack Overflow用户

发布于 2022-08-09 10:18:13

整个请求都是这样的。

代码语言:javascript
复制
$soapurl = "http://some_ip_endpoint";
$date = date("Y-m-d h:i:sa");
$requestID = (new DateTime())->getTimestamp();


// Make your own custom request.

$xml_post_string = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Header/>
        <soapenv:Body>
        <ban:someMthod>
            <chnlNum>somenumber</chnlNum>
            <chnlPasWd>some password</chnlPasWd>
            <userNum>some number</userNum>
            <amount>some amount</amount>
            <requestDate>' . $date . '</requestDate>
            <requestId>' . $requestID . '</requestId>
        </ban:someMethod>
        </soapenv:Body>
        </soapenv:Envelope>';


// Don't for get to mention a proper header 

    $headers = array(
            "Content-Type: text/xml; charset=UTF-8",
            "Pragma: no-cache",
            "Content-length: " . strlen($xml_post_string),
            "Connection: Keep-Alive"
        );


// The actual curl request.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $soapurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);


// Get a response and filter it out accordingly 

$response = curl_exec($ch);
curl_close($ch);
$xml = $response;
$xml = preg_replace("/(<\/?)(\w+):([^>]*>)/", '$1$2$3', $xml);
$xml = simplexml_load_string($xml);
$json = json_encode($xml);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61780404

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档