user3718908x100
user3718908x100

Reputation: 8509

Malformed Soap Request With Soap Client

I have the following request that I test successfully with postman:

curl -X POST \
  'https://dig-stage.crane.aero/craneota/CraneOTAService?wsdl=' \
  -H 'Content-Type: text/xml' \
  -H 'Postman-Token: 85f5fd96-5040-497e-9578-02dc63d91267' \
  -H 'cache-control: no-cache' \
  -d '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:impl="http://impl.soap.ws.crane.hititcs.com/">
  <soapenv:Header/>
  <soapenv:Body>
    <impl:GetAirPortMatrix>
        <AirPortMatrixRequest>
          <clientInformation>
            <clientIP>127.0.0.1</clientIP>
            <member>false</member>
            <password>xxxxxx</password>
            <preferredCurrency>xxx</preferredCurrency>
            <preferredLanguage>xx</preferredLanguage>
            <userName>xxxxxx</userName>
          </clientInformation>
      </AirPortMatrixRequest>
    </impl:GetAirPortMatrix>
  </soapenv:Body>
</soapenv:Envelope>'

Now I am trying to use PHP soap client to execute that same request from my controller:

$client = new SoapClient("https://dig-stage.crane.aero/craneota/CraneOTAService?wsdl");
$response = $client->__soapCall("GetAirPortMatrix", ["AirportMatrixRequest" => [
      'clientIP' => '127.0.0.1',
      'member' => false,
      'password'   => 'xxxxxx',
      'preferredCurrency' => 'xxx',
      'userName' => 'xxxxxx'
]]);

However I keep getting a server error:

ERR_INVALID_REQUEST : Client information and Request object must be set properly

At this point I'm certain I'm not forming the request correctly in PHP as I did in Postman.

Upvotes: 0

Views: 771

Answers (1)

Mika&#235;l DELSOL
Mika&#235;l DELSOL

Reputation: 760

If you want to be certain without a doubt to form a valid request, use a WSDL to PHP generator. Using this type of generator will lead you to a PHP SDK with classes that match the request and response data and the classes to send the request. Then you just have to instanciate objects then pass the request data object to the class that easily permit to send the request and handle the response all using an OOP approach. In addition, you'll have full autocompletion using an IDE such as PhpStorm or Eclipse PDT.

Try the PackageGenerator project.

Upvotes: 1

Related Questions