Home » Php » php – curl – SPNEGO cannot find mechanisms to negotiate

php – curl – SPNEGO cannot find mechanisms to negotiate

Posted by: admin July 12, 2020 Leave a comment

Questions:

i’m trying to use php-curl with a microsoft web service: Here is my code (working on windows 10 with wamp):

<?php

$location = "http://10.0.100.19:7058/FOLDER12013/OData/Company('TEST')/WS_Clienti";
$handle = curl_init($location);

$credentials = 'CPGNET\username:password';
$action =


$proxy =  '11.22.33.44:8123';
$headers = [
    'Method: GET',
    'User-Agent: PHP-SOAP-CURL',
    'Content-Type: text/xml; charset=utf-8',
];


// Authentication
curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_NTLM | CURLAUTH_BASIC | CURLAUTH_GSSNEGOTIATE | CURLAUTH_ANY);
curl_setopt($handle, CURLOPT_USERPWD, $credentials);

curl_setopt($handle, CURLINFO_HEADER_OUT, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($handle, CURLOPT_PROXY,$proxy);

$response = "";
echo("<pre>");
$response = curl_exec($handle);

$url_info = curl_getinfo($handle);

print_r($url_info);

echo(htmlentities($response));
echo("</pre>");

When I try to use this code from centos 7 (or ubuntu 15) I have an error 401 unautorized. Php, curl, libcurl have the same version on windows and linux (and all extensions are equal checking with phpinfo). So, I’m trying to use curl from linux:

curl --negotiate -u "CPGNET\username:password" --proxy 11.22.33.44:8123 "http://10.0.100.19:7058/FOLDER12013/OData/Company('TEST')/WS_Clienti" -v

But I have an error:

* gss_init_sec_context() failed: : SPNEGO cannot find mechanisms to negotiate

Please someone can help me. I don’t understand why from linux this not works.
Thank you

How to&Answers:

a bit old question, but …

It could be you are hitting a problem with a ntlm authentication via gssapi of curl. Please take a look to following links: