简体   繁体   中英

SOAP Authentication issue

I'm having authentication issues with the SOAP server I'm trying to connect to.

I need to use this address for retreiving the wsdl info https://profitweb.afasonline.nl/profitservices/updateconnector.asmx?wsdl

When I enter this address in the browser, a username and password is asked. Filling in my username and password, the WSLD XML is shown.

So, I'm using this peace of PHP code

$wsdl = "https://profitweb.afasonline.nl/profitservices/updateconnector.asmx?wsdl";
$url = "https://profitweb.afasonline.nl/profitservices/updateconnector.asmx";
$login = 'username';
$password = 'password';

$client = new SoapClient( $wsdl, array('login' => $login, 'password' => $password));

But then I get the following error:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://profitweb.afasonline.nl/profitservices/updateconnector.asmx?wsdl' : failed to load external entity "https://profitweb.afasonline.nl/profitservices/updateconnector.asmx?wsdl" in C:\xampp\htdocs\test.nl\soap.php:8 Stack trace: #0 C:\xampp\htdocs\test.nl\soap.php(8): SoapClient->SoapClient('https://profitw...', Array) #1 {main} thrown in C:\xampp\htdocs\test.nl\soap.php on line 8

This doesn't look like a authentication error. However if I download the wsdl file manually, save it local and then use that file for creating a new SoapClient , I'm not getting any errors when initializing the SoapClient.

But if I then do a request

$client->__doRequest($request, $url, 'Execute', '1');

I'm getting this __getLastResponseHeaders

HTTP/1.1 401 Unauthorized ( The server requires authorization to fulfill the request. Access to the Web server is denied. Contact the server administrator. ) WWW-Authenticate: Negotiate WWW-Authenticate: Kerberos WWW-Authenticate: NTLM Connection: Keep-Alive Pragma: no-cache Cache-Control: no-cache Content-Type: text/html Content-Length: 3184

So that's giving me the idea that I'm running into authentication issues! Read a lot of posts already about this issue, but couldn't find the right answer jet!

EDIT Adding this to the options

'trace' => 1, 'exceptions' => 0

Give's me indeed an authentication error.

Warning: SoapClient::SoapClient(https://profitweb.afasonline.nl/profitservices/updateconnector.asmx?wsdl): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized ( The server requires authorization to fulfill the request. Access to the Web server is denied. Cont in C:\xampp\htdocs\test.nl\soap.php on line 9

AFAS still uses NuSOAP (4.x) instead of SOAP (5.x). I'm using the noiselabs/nusoap-bundle which can be found on Github to access AFAS myself.

Basically you get these kind of errors when you connect with Afasonline Soap API in PHP

Below is an example how to connect and request

NOTE: First you need to know some concept about Afasonline API before connecting as you know Afasonline uses Nusoap with Windows NTLM Authentication so in order connect you need domain name for NTLM which is “AOL” in case Afasonline. You can read more about NTLM by searching over the internet. Further you need the following parameter also in order to connect environmentId (it always starts with OXXXXXXX), userId, Password, connectorID.

I am going show an example for Getconnector with connectorID (SSS_werkgever_vacatures) to get all the jobs but method of authentication is same for all the connectors.

Click here to see Tutorial in Detail

 <?php require_once('lib/nusoap.php'); $wsdl = 'https://profitweb.afasonline.nl/profitservices/getconnector.asmx?wsdl'; $client = new nusoap_client($wsdl, true); $client->setCredentials("AOL" . '\\\\' . "53175.Webbio", "Password!", 'ntlm'); $client->setUseCurl(true); $client->useHTTPPersistentConnection(); $client->setCurlOption(CURLOPT_USERPWD, '53175.webbio:Password!'); $xml_array['environmentId'] = 'O12343AA'; $xml_array['userId'] = "41258.Webbio"; $xml_array['password'] = "Password"; $xml_array['logonAs'] = ""; $xml_array['connectorId'] = "SSS_werkgever_vacatures"; $xml_array['filtersXml'] = ""; $err = $client->getError(); if ($err) { echo '<h2>Constructor error</h2><pre>' . $err . '</pre>'; echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>'; exit(); } $result = $client->call('GetData', array('parameters' => $xml_array), '', '', false, true); // var_dump($result); header('Content-Type: application/xml'); print_r($result["GetDataResult"]); ?> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM