问题
我正在尝试与未提供WSDL的提供商的API进行集成-我假设我必须提出非WSDL请求。但是,我提出的每个请求都给我一个“错误请求”结果。我以前从未使用过SOAP API,因此我对这里做错的事情感到迷茫。
我尝试使用__soapCall();函数调用API的端点,并使用对象构造参数以尝试按照API文档的要求对其进行格式化。
使用getLastRequest()生成和转储请求时,我注意到我的函数调用将所有内容包装在“ param0”结构中,该结构与API端点期望的结构不匹配。
所以我本质上是在问两件事: 1.导致错误请求结果的原因是什么,或者有什么方法可以诊断出来? 2.这个额外的结构是否将我的参数包装在错误的结果中?我该如何避免?
代码:
这是我的带有选项的构造函数。据我了解,如果我没有wsdl,我应该传递“ null”(我创建了一个扩展SoapClient的类以添加一些将构造它的辅助函数,因此为什么我要使用parent :: __ construct)>
$opts = array(
"location" => $url,
"uri" => "https://trakpak.co.uk/API/",
"trace" => true
);
parent::__construct( null, $opts );
这是我对实际SOAP函数的调用:
$this->base_function = "CreateShipment";
$this->parameters = new \stdClass;
$this->parameters->ApiKey = "fff";
$result = $this->__soapCall( $this->base_function, [ $this->base_function => $this->parameters ] );
这将返回:
SOAP Error Code: HTTP: Bad Request
如果我放弃了上一个请求,这就是我收到的信息:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="https://trakpak.co.uk/API/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:CreateShipment>
<param0 xsi:type="SOAP-ENC:Struct">
<ApiKey xsi:type="xsd:string">FFF</ApiKey>
</param0>
</ns1:CreateShipment>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我不确定这是假定的样子,因为我以前从未真正使用过SOAP。
API正在请求类似这样的内容:
<CreateShipment>
<ApiKey>FFF</ApiKey>
</CreateShipment>
似乎我的请求可能实际上从未到达SOAP端点,因为转储响应完全是空白。当API不期望的时候,我的请求本身在CreateShipment标记中似乎也有多余的包装param0结构。
更新
我设法解决了“ param0”问题,现在我的请求如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="https://trakpak.co.uk/API/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:CreateShipment>
<ApiKey xsi:type="xsd:string">FFF</ApiKey>
</ns1:CreateShipment>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
其格式完全符合他们的要求,但我仍然得到
SOAP Error Code: HTTP: Bad Request
,服务器未响应。