php - 使用 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 中正确地形成请求。
解决方案
如果您想毫无疑问地确定形成一个有效的请求,请使用 WSDL 到 PHP 生成器。使用这种类型的生成器将引导您使用 PHP SDK,其中包含与请求和响应数据匹配的类以及发送请求的类。然后,您只需实例化对象,然后将请求数据对象传递给易于允许发送请求并使用 OOP 方法处理响应的类。此外,您将使用诸如 PhpStorm 或 Eclipse PDT 之类的 IDE 进行完全自动完成。
试试PackageGenerator项目。
推荐阅读
- reactjs - 调整 MUI 中自动完成下拉菜单的字体大小
- javascript - React JS 上下文,TypeError:无法读取未定义的属性
- python - Python 无法下载带有无扩展名的动态 URL 的 excel 文件
- android - 如何使用 Jetpack Compose 使 LinearProgressIndicator 宽度动态化
- javascript - React.js 中的 Axios 网络错误 createError.js:16
- javascript - 如何在不和谐中找到消息的作者,以及如何使用它来确定它是否具有命令的正确权限
- javascript - VictoryChart 不更改日期数据
- ios - 修复 iOS 15 UINavigationBar
- android - Kotlin - 事件前的 WorkManager 通知
- html - TailwindCSS - 将所有网格项目设置为相同的高度