drn34916
2018-07-16 06:10
浏览 894
已采纳

使用soapenv的SOAP请求

I have the following code for connecting to a soap client. I am struggling hard to find how to create a proper soap request.

$soap = new SoapClient($apiWsdl,
        array("soap_version" => SOAP_1_1,
              "trace" => 1));
var_dump($soap);
echo $soap->__getLastResponse();
try{
    $data = $soap->login($apiUser,$apiKey);
}
catch (SoapFault $soapFault) {
    echo "Request :<br>", htmlentities($soap->__getLastRequest()), "<br>";
    echo "Response :<br>", htmlentities($soap->__getLastResponse()), "<br>";

}

I get the following XML built:

<?xml version="1.0" encoding="UTF-8"?> \<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:login><username xsi:type="xsd:string">XXXXXXX</username><apiKey xsi:type="xsd:string">XXXXXXXX</apiKey></ns1:login></SOAP-ENV:Body></SOAP-ENV:Envelope> 


Which returns be a forbidden access.

However the server is accepting only request of the following form



<soapenv:Envelope 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:urn="urn:Magento">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:login soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <username xsi:type="xsd:string">XXXXXXX</username>
         <apiKey xsi:type="xsd:string">XXXXXX</apiKey>
      </urn:login>
   </soapenv:Body>
</soapenv:Envelope>

Can somebody please let me know what mistake I am making in the code.

图片转代码服务由CSDN问答提供 功能建议

我有以下代码连接到soap客户端。 我正在努力寻找如何创建一个合适的肥皂请求。

  $ soap = new SoapClient($ apiWsdl,
 array(“soap_version”=&gt; SOAP_1_1,
“trace”=&gt; 1)); 
var_dump(  $ soap); 
echo $ soap-&gt; __ getLastResponse(); 
try {
 $ data = $ soap-&gt; login($ apiUser,$ apiKey); 
} 
catch(SoapFault $ soapFault){
  echo“Request:&lt; br&gt;”,htmlentities($ soap-&gt; __ getLastRequest()),“&lt; br&gt;”; 
 echo“Response:&lt; br&gt;”,htmlentities($ soap-&gt; __ getLastResponse(  )),“&lt; br&gt;”; 
 
} 
   
 
 

我构建了以下XML:

  &lt;?xml version =“1.0”encoding =“UTF-8”?&gt;  \&lt; SOAP-ENV:Envelope xmlns:SOAP-ENV =“http://schemas.xmlsoap.org/soap/envelope/”xmlns:ns1 =“urn:Magento”xmlns:xsd =“http:// www。  w3.org/2001/XMLSchema“xmlns:xsi =”http://www.w3.org/2001/XMLSchema-instance“xmlns:SOAP-ENC =”http://schemas.xmlsoap.org/soap/encoding/  “SOAP-ENV:encodingStyle =”http://schemas.xmlsoap.org/soap/encoding/“&gt;&lt; SOAP-ENV:Body&gt;&lt; ns1:login&gt;&lt; username xsi:type =”xsd:string  “&gt; XXXXXXX&lt; / username&gt;&lt; apiKey xsi:type =”xsd:string“&gt; XXXXXXXX&lt; / apiKey&gt;&lt; / ns1:login&gt;&lt; / SOAP-ENV:Body&gt;&lt; / SOAP-ENV: 包络GT;  
 
 
什么返回是禁止访问。
 
然而,服务器只接受以下形式的请求
 
 
 
&lt; soapenv:Envelope 
 xmlns:xsi =“http:// www  .w3.org / 2001 / XMLSchema-instance“
 xmlns:xsd =”http://www.w3.org/2001/XMLSchema“
 xmlns:soapenv =”http://schemas.xmlsoap.org/soap  / envelope /“
 xmlns:urn =”urn:Magento“&gt; 
&lt; soapenv:Header /&gt; 
&lt; soapenv:Body&gt; 
&lt; urn:login soapenv:encodingStyle =”http:/  /schemas.xmlsoap.org/soap/encoding/">
&lt; username xsi:type =“xsd:string”&gt; XXXXXXX&lt; / username&gt; 
&lt; apiKey xsi:type =“xsd:string”&gt  ; XXXXXX&lt; / apiKey&gt; 
&lt; / urn:login&gt; 
&lt; / soapenv:Body&gt; 
&lt; / soapenv:Envelope&gt; 
   
 
 

Can 有人请让我知道我在代码中犯了什么错误。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutu9810 2018-07-16 06:29
    已采纳

    It looks like you have a typo right after the XML tags. There is a backslash that should not be there. This could trigger your errors.

    HTH, Jim

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题