繁体   English   中英

PHP soap xml请求

[英]PHP soap xml request

我曾尝试在网上四处寻找和搜寻很多东西,但我不知道该怎么做。

我想使用标头和XML代码发出SOAP请求。

这就是我走了多远:创建了一个保存标头信息的变量:

$headers = array(
        "POST /somefile.asmx HTTP/1.1",
        "Host: a ip adress",
        "Content-Type: application/soap+xml; charset=utf-8",
        "Content-Length: ".strlen($xml_post_string)
    );

我想发送的xml如下所示:

<?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>
    <GetViVaDataT xmlns="http://www.somesite.se/somefile.wsdl">
      <PlatsId>int</PlatsId>
    </GetViVaDataT>
  </soap:Body>
</soap:Envelope>

但是我不知道该怎么走。 我正在使用肥皂1.2。

如果其他人有与我相同的问题,那么这就是我为使其正常工作所做的事情。

$soapAction = 'http://www.somesite.com/path/to/file/file.wsdl/function';


    $xml = '<?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>
      <GetViVaDataT xmlns="http://www.somesite.se/somefile.wsdl">
        <PlatsId>int</PlatsId>
      </GetViVaDataT>
    </soap:Body>
   </soap:Envelope>';

    $headers = array(
        "POST /site.asmx HTTP/1.1",
        "Host: a ip adress",
        "Content-Type: application/soap+xml; charset=utf-8",
        "Content-Length: ".strlen($xml),
        'SOAPAction:' .$soapAction
    );

    $curlData = $xml;
    $url='http://site/file.asmx';
    $curl = curl_init();

    curl_setopt ($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl,CURLOPT_TIMEOUT,120);
    curl_setopt($curl,CURLOPT_ENCODING,'xml');

    curl_setopt($curl,CURLOPT_HTTPHEADER,$headers);

    curl_setopt ($curl, CURLOPT_POST, 1);
    curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);

    $result = curl_exec($curl);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM