使用 PHP 连接到示例 SOAP 1.1
问题描述:
您好,我需要在 php 中使用密码、用户名和 SourceId 连接到 SOAP 网络服务.SOAP 请求是:
Hello i need to connect to SOAP web services with password, username and SourceId in php. the SOAP request is:
POST /webservices/AgentOnlineReservation.asmx HTTP/1.1
Host: 54.228.189.53
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/GetHotelsData"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetHotelsData xmlns="http://tempuri.org/">
<SourceId>string</SourceId>
<UserName>string</UserName>
<Password>string</Password>
</GetHotelsData>
</soap:Body>
</soap:Envelope>
请帮帮我.
答
使用原生的 SoapClient 库:
$client = new SoapClient('linkhere.com/AgentOnlineReservation.asmx?wsdl');
$response = $client->GetHotelsData(array(
'SourceId' => '...',
'UserName' => '...',
'Password' => '...'
));
print_r($response);
SoapClient 调用中传递的链接是 WSDL(Web 服务描述语言)文件.
The link passed in the SoapClient call is the WSDL (Web Service Description Language) file.