我有以下代码用于连接到Soap客户端。我正在努力寻找如何创建适当的肥皂请求。
$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>";
}
我建立了以下XML:
<?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>
有人可以让我知道我在代码中犯了什么错误吗?
答案 0 :(得分:0)
您似乎在XML标记后有一个错字。有一个反斜杠不应该在那里。这可能会触发您的错误。
HTH,吉姆