PHP SOAPCall 输入为空
PHP SOAPCall Input is null
我收到以下错误:
Fatal error: Uncaught SoapFault exception: [s:Client] Service
operation Pickup_Cancel failed due to validation errors: Input is null
这是我的代码:
$client = new SoapClient("https://etrack.postaplus.net/APIService/PostaWebClient.svc?singleWsdl", array("trace" => 1, "exception" => 0));
$params = array(
"CodeStation" => `BEY`,
"PickupNumber" => `1`,
"Reason" => `test reason`,
"Password" => `sss`,
"ShipperAccount" => `acc`,
"UserName" => `acc`,
);
$client->Pickup_Cancel($params);
你没有问的问题的答案可能是:将反引号 (`) 替换为单引号 (')
-- 编辑。那不是问题。
情况是这样的。 SOAP 可能很难上手。我的经验是使用好的 soap class 或者只是非 wsdl 模式。在文档中阅读此内容:https://www.php.net/manual/en/soapclient.soapcall.php
所以不要这样做:
$return = $soapClient->functionName($data);
但是这个:
$return = $soapClient->__SoapCall('functionName', $data);
同时了解服务器需要什么,将 WSDL url 加载到客户端,如 SoapUI https://www.soapui.org/(免费)。这让您可以检查 SoapServer 是否正常工作以及您应该如何通过调用处理它。
在您的情况下,WSDL 声明如下:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:pos="http://schemas.datacontract.org/2004/07/PostaWebClient">
<soapenv:Header/>
<soapenv:Body>
<tem:Pickup_Cancel>
<!--Optional:-->
<tem:CLIENTINFO>
<!--Optional:-->
<pos:CodeStation>asd</pos:CodeStation>
<!--Optional:-->
<pos:Password>asd</pos:Password>
<!--Optional:-->
<pos:ShipperAccount>asd</pos:ShipperAccount>
<!--Optional:-->
<pos:UserName>asd</pos:UserName>
</tem:CLIENTINFO>
<!--Optional:-->
<tem:PickupNumber>asd</tem:PickupNumber>
<!--Optional:-->
<tem:Reason>asd</tem:Reason>
</tem:Pickup_Cancel>
</soapenv:Body>
</soapenv:Envelope>
转换成这个 PHP 代码:
$client = new SoapClient("https://etrack.postaplus.net/APIService/PostaWebClient.svc?singleWsdl");
$params = [
'Pickup_Cancel' => [
'CLIENTINFO' => [
'Password' => 'sss',
'ShipperAccount' => 'acc',
'UserName' => 'acc',
'CodeStation' => '',
],
'PickupNumber' => '',
'Reason' => '',
],
];
$client->__SoapCall("Pickup_Cancel", $params);
看看数组如何匹配 WSDL xml 格式?
这也应该为您提供继续进行所需的反馈。如果没有,可能是时候寻求 'real' 帮助了 :) 祝你好运。
我收到以下错误:
Fatal error: Uncaught SoapFault exception: [s:Client] Service operation Pickup_Cancel failed due to validation errors: Input is null
这是我的代码:
$client = new SoapClient("https://etrack.postaplus.net/APIService/PostaWebClient.svc?singleWsdl", array("trace" => 1, "exception" => 0));
$params = array(
"CodeStation" => `BEY`,
"PickupNumber" => `1`,
"Reason" => `test reason`,
"Password" => `sss`,
"ShipperAccount" => `acc`,
"UserName" => `acc`,
);
$client->Pickup_Cancel($params);
你没有问的问题的答案可能是:将反引号 (`) 替换为单引号 (')
-- 编辑。那不是问题。
情况是这样的。 SOAP 可能很难上手。我的经验是使用好的 soap class 或者只是非 wsdl 模式。在文档中阅读此内容:https://www.php.net/manual/en/soapclient.soapcall.php
所以不要这样做:
$return = $soapClient->functionName($data);
但是这个:
$return = $soapClient->__SoapCall('functionName', $data);
同时了解服务器需要什么,将 WSDL url 加载到客户端,如 SoapUI https://www.soapui.org/(免费)。这让您可以检查 SoapServer 是否正常工作以及您应该如何通过调用处理它。
在您的情况下,WSDL 声明如下:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:pos="http://schemas.datacontract.org/2004/07/PostaWebClient">
<soapenv:Header/>
<soapenv:Body>
<tem:Pickup_Cancel>
<!--Optional:-->
<tem:CLIENTINFO>
<!--Optional:-->
<pos:CodeStation>asd</pos:CodeStation>
<!--Optional:-->
<pos:Password>asd</pos:Password>
<!--Optional:-->
<pos:ShipperAccount>asd</pos:ShipperAccount>
<!--Optional:-->
<pos:UserName>asd</pos:UserName>
</tem:CLIENTINFO>
<!--Optional:-->
<tem:PickupNumber>asd</tem:PickupNumber>
<!--Optional:-->
<tem:Reason>asd</tem:Reason>
</tem:Pickup_Cancel>
</soapenv:Body>
</soapenv:Envelope>
转换成这个 PHP 代码:
$client = new SoapClient("https://etrack.postaplus.net/APIService/PostaWebClient.svc?singleWsdl");
$params = [
'Pickup_Cancel' => [
'CLIENTINFO' => [
'Password' => 'sss',
'ShipperAccount' => 'acc',
'UserName' => 'acc',
'CodeStation' => '',
],
'PickupNumber' => '',
'Reason' => '',
],
];
$client->__SoapCall("Pickup_Cancel", $params);
看看数组如何匹配 WSDL xml 格式?
这也应该为您提供继续进行所需的反馈。如果没有,可能是时候寻求 'real' 帮助了 :) 祝你好运。