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

非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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 spring后端vue前端
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题