嗨大家我正在尝试发出请求并获得对我的SOAP请求进行身份验证的响应。
我尝试了很多不同的选项,但是这一个是唯一一个给我回复的选项(即使是错误404)。
这是我的代码
$client = new SOAPClient('http://devapi.stellatravelgateway.stellatravelservices.co.uk/DirectoryService.svc?singleWsdl',
array(
'location' => 'http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService/IDirectoryService/Authenticate',
'trace' => 1,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
)
);
$request = array(
"BranchCode" => "xxx",
"UserName" => "xxx",
"Password" => "xxx",
"Application" => "xxx",
"Client" => "x",
"BranchID" => 0
);
$result = array();
try {
$result = $client->__soapCall('Authenticate', $request);
} catch (SoapFault $e) {
echo "SOAP Fault: ".$e->getMessage()."<br />\n";
}
echo "<pre>";
echo htmlspecialchars($client->__getLastRequestHeaders())."\n";
echo htmlspecialchars($client->__getLastRequest())."\n";
echo "Response:\n".htmlspecialchars($client->__getLastResponseHeaders())."\n";
echo htmlspecialchars($client->__getLastResponse())."\n";
echo "</pre>";
var_dump($result);
我做错了什么?我没有得到任何回应我得到了
POST /DirectoryService/IDirectoryService/Authenticate HTTP/1.1
Host: stellatravelgateway.stellatravelservices.co.uk
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.5.38
Content-Type: text/xml; charset=utf-8
SOAPAction:"http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService/IDirectoryService/Authenticate"
Content-Length: 367
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService"><SOAP-ENV:Body><ns1:Authenticate/><param1>xxx</param1><param2>xxx</param2><param3>xxx</param3><param4>x</param4><param5>0</param5></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response:
HTTP/1.1 404 Not Found // Here
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Mon, 19 Mar 2018 13:34:51 GMT
Connection: close
Content-Length: 1245
这是我需要发送的确切请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dir="http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService">
<soapenv:Header/>
<soapenv:Body>
<dir:Authenticate>
<dir:authenticateRequest BranchCode="xxx" UserName="xxx" Password="xxx" Application="xxx" Client="xxx">
<dir:BranchID>xxx</dir:BranchID>
</dir:authenticateRequest>
</dir:Authenticate>
</soapenv:Body>
</soapenv:Envelope>
编辑:这是我从SoapUI获得的原始数据:
POST http://stellatravelgateway.stellatravelservices.co.uk/AirService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService/IDirectoryService/Authenticate"
Content-Length: 602
Host: stellatravelgateway.stellatravelservices.co.uk
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
请各位帮忙会很棒,有任何反馈意见!提前谢谢。
答案 0 :(得分:3)
从选项中删除'location'参数,并调用Authenticate()函数,如下所示:
try {
$result = $client->Authenticate(array('authenticateRequest'=>$request));
} catch (SoapFault $e) {
结果:
POST /DirectoryService.svc HTTP/1.1
Host: devapi.stellatravelgateway.stellatravelservices.co.uk
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.6.32
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService/IDirectoryService/Authenticate"
Content-Length: 446
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService"><SOAP-ENV:Body><ns1:Authenticate><ns1:authenticateRequest BranchCode="xxx" UserName="xxx" Password="xxx" Application="xxx" Client="x"><ns1:BranchID>0</ns1:BranchID></ns1:authenticateRequest></ns1:Authenticate></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Date: Mon, 19 Mar 2018 14:06:43 GMT
Connection: close
Content-Length: 522
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><AuthenticateResponse xmlns="http://stellatravelgateway.stellatravelservices.co.uk/DirectoryService"><AuthenticateResult Success="false" Narrative="Invalid details. Please check request. " CanBeOpenedInEditMode="false" ErrorCode="200002"><Token xsi:nil="true"/><Expiry xsi:nil="true"/></AuthenticateResult></AuthenticateResponse></s:Body></s:Envelope>
object(stdClass)#2 (1) {
["AuthenticateResult"]=>
object(stdClass)#3 (6) {
["Success"]=>
bool(false)
["Narrative"]=>
string(39) "Invalid details. Please check request. "
["CanBeOpenedInEditMode"]=>
bool(false)
["ErrorCode"]=>
int(200002)
["Token"]=>
NULL
["Expiry"]=>
NULL
}
}
答案 1 :(得分:0)
尝试在创建客户端时将凭据作为otions传递:
$client = new \SoapClient('http://devapi.stellatravelgateway.stellatravelservices.co.uk/DirectoryService.svc?singleWsdl', array(
'login' => $username,
'password' => $password,
'exceptions' => true,
'trace' => true
));