Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eurotours XML interface SOAP HTTP unauthorized

Tags:

php

soap

xml

I try to make an example from Eurotours XML interface but all SOAP function calls give me

PHP Fatal error: Uncaught SoapFault exception: [HTTP] Unauthorized

Here is my code:

$soapClient = new SoapClient("https://ws.eurotours.at/accommodation/development/AccommodationService?wsdl",array('trace' => true));
$functions = $soapClient -> __getFunctions();
$soapClient -> getLanguages(array("Client"=>"TESTXMLB2B"));

it is only the client from test on documentation, I don't know if I wrong with something.

Here is my full exception and I want know if really is an authorized problem or only because I'm doing a mistake when make the call:

object(SoapFault)#2 (9) {
  ["message":protected]=>
  string(12) "Unauthorized"
  ["string":"Exception":private]=>
  string(0) ""
  ["code":protected]=>
  int(0)
  ["file":protected]=>
  string(34) "/home/laurentiu/teste/testswap.php"
  ["line":protected]=>
  int(5)
  ["trace":"Exception":private]=>
  array(3) {
    [0]=>
    array(4) {
      ["function"]=>
      string(11) "__doRequest"
      ["class"]=>
      string(10) "SoapClient"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(5) {
        [0]=>
        string(224) "<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.eurotours.at/"><SOAP-ENV:Body><ns1:getLanguages/></SOAP-ENV:Body></SOAP-ENV:Envelope>
"
        [1]=>
        string(74) "https://ws.eurotours.at:443/accommodation/development/AccommodationService"
        [2]=>
        string(0) ""
        [3]=>
        int(1)
        [4]=>
        int(0)
      }
    }
    [1]=>
    array(6) {
      ["file"]=>
      string(34) "/home/laurentiu/teste/testswap.php"
      ["line"]=>
      int(5)
      ["function"]=>
      string(6) "__call"
      ["class"]=>
      string(10) "SoapClient"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(2) {
        [0]=>
        string(12) "getLanguages"
        [1]=>
        array(1) {
          [0]=>
          array(1) {
            ["Client"]=>
            string(10) "TESTXMLB2C"
          }
        }
      }
    }
    [2]=>
    array(6) {
      ["file"]=>
      string(34) "/home/laurentiu/teste/testswap.php"
      ["line"]=>
      int(5)
      ["function"]=>
      string(12) "getLanguages"
      ["class"]=>
      string(10) "SoapClient"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(1) {
        [0]=>
        array(1) {
          ["Client"]=>
          string(10) "TESTXMLB2C"
        }
      }
    }
  }
  ["previous":"Exception":private]=>
  NULL
  ["faultstring"]=>
  string(12) "Unauthorized"
  ["faultcode"]=>
  string(4) "HTTP"
};
like image 525
Laurentiu Avatar asked Jul 31 '14 06:07

Laurentiu


1 Answers

I don't now their service, but as commented "HTTP Unauthorized" signals HTTP status code 401 which means you need to provide a username and password on the HTTP level.

Contact that service vendor and get your login (see "Get your login" on http://xml.eurotours.at/overview), then use the username and password with SoapClient.

With the SoapClient you pass username and password via the options parameter:

$soapClient = new SoapClient(
    "https://ws.eurotours.at/accommodation/development/AccommodationService?wsdl",
    array(
        'trace'    => true,
        'login'    => 'your username',
        'password' => 'your password',
    )
);

This would use the default authentication method of SOAP_AUTHENTICATION_BASIC (see basic authentication). **SoapClient* also allows a second authentication method by setting the "authentication" option to SOAP_AUTHENTICATION_DIGEST for digest authentication. This information might be useful in case the server requires with type of authentication. However in your case, according to the response headers ($soapClient->__getLastResponseHeaders()), it's "Basic":

HTTP/1.1 401 Unauthorized
Date: Thu, 31 Jul 2014 09:35:27 GMT
Server: Apache
X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)
WWW-Authenticate: Basic realm="webservice-realm"
Content-Length: 1073
Content-Language:
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

(highlight by me)

Here is also the response body which SoapClient can not provide but which can be obtained via HTTP inspection (proxy) or by just doing the HTTP request your own:

GlassFish Response to the SOAP Request

Image transcription: HTTP Status 401 -

type Status report

message

descriptionThis request requires HTTP authentication ().

GlassFish Server Open Source Edition 3.1.2.2

like image 105
hakre Avatar answered Oct 07 '22 05:10

hakre