首页 > 解决方案 > 使用 Soap 客户端的格式错误的 Soap 请求

问题描述

我有以下请求,我用邮递员成功测试:

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

现在我正在尝试使用 PHP soap 客户端从我的控制器执行相同的请求:

$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'
]]);

但是我不断收到服务器错误:

ERR_INVALID_REQUEST : Client information and Request object must be set properly

在这一点上,我确定我没有像在 Postman 中那样在 PHP 中正确地形成请求。

标签: phpsoap-client

解决方案


如果您想毫无疑问地确定形成一个有效的请求,请使用 WSDL 到 PHP 生成器。使用这种类型的生成器将引导您使用 PHP SDK,其中包含与请求和响应数据匹配的类以及发送请求的类。然后,您只需实例化对象,然后将请求数据对象传递给易于允许发送请求并使用 OOP 方法处理响应的类。此外,您将使用诸如 PhpStorm 或 Eclipse PDT 之类的 IDE 进行完全自动完成。

试试PackageGenerator项目。


推荐阅读