dongtuoao7987
2018-03-19 13:43
浏览 64
已采纳

Soap请求验证php

Hi Guys I am trying to make a request and get a response for authenticating my SOAP request.

I tried many different options but this one was the only one which gave me response(even an error 404).

This is my code

$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 />
";
}

 echo "<pre>";
 echo htmlspecialchars($client->__getLastRequestHeaders())."
";
 echo htmlspecialchars($client->__getLastRequest())."
";
 echo "Response:
".htmlspecialchars($client->__getLastResponseHeaders())."
";
 echo htmlspecialchars($client->__getLastResponse())."
";
 echo "</pre>"; 

 var_dump($result);

What am i doing wrong? I dont get any response I get thsi

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

This is the exact request I need to send :

<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>

EDIT: This is what I get on raw from 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)

Please guys any help would be great, any feedback! Thank you in advance.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douchuoliu4422 2018-03-19 14:02
    已采纳

    Remove the 'location' param from options, and call the Authenticate() function like this:

    try {
        $result = $client->Authenticate(array('authenticateRequest'=>$request));
    } catch (SoapFault $e) {
    

    result:

    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
      }
    }
    
    已采纳该答案
    打赏 评论
  • duanliao3826 2018-03-19 13:53

    Try to pass the credentials as otions when creating the client:

    $client = new \SoapClient('http://devapi.stellatravelgateway.stellatravelservices.co.uk/DirectoryService.svc?singleWsdl', array(
        'login' => $username,
        'password' => $password,
        'exceptions' => true,
        'trace' => true
    ));
    
    打赏 评论

相关推荐 更多相似问题