I would like to connect with API - send request and get data.
First, I get all the available functions:
$client = new SoapClient('https://website.com/api.asmx?wsdl');
print_r($client->__getFunctions());
And I display array, like this:
[0] => CheckExampleResponse CheckExample(CheckExample $parameters)
So, I must use this way:
$client->CheckExample($params);
but, I don't know how to send this XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="XmlServices">
<soapenv:Header/>
<soapenv:Body>
<xs:GetExample>
<xs:request>
<xs:Credentials>
<xs:UserName>?</xs:UserName>
<xs:Password>?</xs:Password>
<xs:PostlId>?</xs:HotelId>
</xs:Credentials>
<xs:DataTest>2015-01-01T00:00:00</xs:DataTest>
<xs:DataTest2>2015-01-02T23:59:59</xs:DataTest2>
<xs:StatusTest>publish</xs:StatusTest>
</xs:request>
</xs:GetExample>
</soapenv:Body>
</soapenv:Envelope>
When I pass this XML string as an argument to CheckExample
, I get this error: "Request parameter cannot be null."
Thanks.
答案 0 :(得分:0)
GetExample方法也应出现在__getFunctions调用中。然后这应该工作:
<?php
$client = new SoapClient('https://website.com/api.asmx?wsdl');
$soapmessage = [
'request' => [
'Credentials' => [
'UserName' => '?',
'Password' => '?',
'PostlId' => '?'
],
'DataTest' => '2015-01-01T00:00:00',
'DataTest2' => '2015-01-02T23:59:59',
]
];
$result = $client->GetExample($soapmessage);
print_r($result);
答案 1 :(得分:0)
当您将SOAP函数作为SoapClient
的方法调用时,实质上是调用SoapClient::__soapCall()
函数,并将函数名称作为第一个参数传递。因此,理解这个函数的参数是很好的。
您可以看到要传递参数,您需要传递一个数组。这必须与SOAP服务器期望的相匹配;详细信息可以在WSDL中找到,并且不会通过调用SoapClient::__getFunctions()
来显示。如果您不想阅读WSDL,SOAP服务提供者还应提供API文档以确定正确的值。
值得记住的是,即使SOAP函数不需要任何参数,仍然必须将空数组传递给PHP函数。