douleng3463 2019-08-12 20:54
浏览 238

非WSDL Soap请求“错误请求”

The Problem

i'm trying to integrate with an API from a provider that has not given me a WSDL--i'm assuming that i'll have to make Non-WSDL requests. however, every request i'm making is giving me a "Bad Request" result. i've never worked with a SOAP API before so i'm kind of lost on what i'm doing wrong here.

i've attempted to use the __soapCall(); function to call the API's endpoint and have constructed parameters using an object to try to format it the way the API documentation is requesting.

when the request is generated and dumped using getLastRequest(), i'm noticing that my function call is wrapping everything in a "param0" struct, which does not match what the API's endpoint expects.

so i'm asking two things essentially: 1. what is causing the Bad Request result or is there a way to diagnose it? 2. is this extra struct my parameters are being wrapped in the result of the error? how do i avoid that?

Code:

here's my constructor with options. from what i understand, if i have no wsdl, i should pass "null" (i've created a class that extends SoapClient to add some helper functions that will construct it, hence why i'm using parent::__construct)

$opts = array(
    "location" => $url,
    "uri" => "https://trakpak.co.uk/API/",
    "trace" => true
);

parent::__construct( null, $opts );

here's my call to the actual SOAP function:

$this->base_function = "CreateShipment";
$this->parameters = new \stdClass;
$this->parameters->ApiKey = "fff";

$result = $this->__soapCall( $this->base_function, [ $this->base_function => $this->parameters ] );

this returns:

SOAP Error Code: HTTP: Bad Request

if i dump my last request, this is what i recieve:

<?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>

i'm unsure if this is how it's supposed to look, as i've never actually worked with SOAP before.

the API is requesting something like this:

<CreateShipment>
   <ApiKey>FFF</ApiKey>
</CreateShipment>

it seems like my request may never actually be reaching the SOAP endpoint, because dumping the response is completely blank. my request itself also seems to have that extra wrapping param0 struct in the CreateShipment tag when the API is not expecting that.

UPDATE

i've managed to work out my "param0" issue, and now my request looks like this:

<?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>

which is formatted exactly how they're requesting it, but i'm still getting

SOAP Error Code: HTTP: Bad Request

and no response from the server.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 win c++ socket
    • ¥15 CanMv K210开发板实现功能
    • ¥15 C# datagridview 栏位进度
    • ¥15 vue3页面el-table页面数据过多
    • ¥100 vue3中融入gRPC-web
    • ¥15 kali环境运行volatility分析android内存文件,缺profile
    • ¥15 写uniapp时遇到的问题
    • ¥15 vs 2008 安装遇到问题
    • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
    • ¥15 找一个网络防御专家,外包的