6

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"
};
hakre
  • 193,403
  • 52
  • 435
  • 836
Laurentiu
  • 574
  • 6
  • 26
  • IIRC *"HTTP Unauthorized"* signals a HTTP status code of 401 - see http://stackoverflow.com/a/6937030/367456 etc. You can enable tracing for the SoapClient to analyze further and/or callbacks within PHP HTTP streams. You should also set error reporting / logging to the highest level. See http://stackoverflow.com/q/845021/367456 and http://stackoverflow.com/a/24711469/367456 (even that is simplexml, libxml is used by SoapClient, too and the HTTP stream as well, there is also default context for all HTTP streams you can hook the same in http://php.net/stream_context_set_default) – hakre Jul 31 '14 at 07:26
  • k , but what i mistake ? i try only make a call for test api from there site , i follow SoapClient from PHP manual and function from api, please be more exactly where i wrong. – Laurentiu Jul 31 '14 at 07:40
  • Ok , that mean need a user and a password for develop test , ok thanks i will contact – Laurentiu Jul 31 '14 at 07:58

1 Answers1

4

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

hakre
  • 193,403
  • 52
  • 435
  • 836
  • 2
    Thank you thank you thank you!! It took me three hours to figure out how to user HTTP Basic Authentication with SOAP. The php.net documentation is as clear as mud for a SOAP amateur like me. – user5670895 Dec 18 '15 at 23:14