4

I have the following code:

$curl = curl_init($query);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $username.':'.$password);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLINFO_HEADER_OUT, 1);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($curl);

I did upload it as AppFog application and it is working fine. The issue is when I try to run the same code on Windows Server 2008 IIS7 or on WAMP.

I get the following message from the server:

HTTP Status 401 - 
type Status report
message description **This request requires HTTP authentication ().**

In seems that I'm not sending the credentials, but 'request_header' has the following value:

POST /example HTTP/1.1
Authorization: Basic example // deliberately removed
Host: example.com
Accept: */*
Connection: close
Content-Length: 0
Content-Type: application/x-www-form-urlencoded

Any ideas what might be the issue? Thanks.

4
  • does the user:pass you're trying to use actually work on that Windows server? Commented Apr 26, 2013 at 21:57
  • I'm trying to connect to third party server. So the credentials and the URL are the same in both cases. Commented Apr 26, 2013 at 22:00
  • @MarcB is right on point. The username and password need to actually authenticate with the server if I remember correctly. If you switched servers, you need to switch your user/pass as appropriate. Commented Apr 26, 2013 at 23:05
  • @Kevin I dont get the point. Example.com is server with ServiceNow instance on it and I have only one username and password combination. It should not matter if I try to access from the Windows Server machine or some other machine. The credentials stay the same. Commented Apr 26, 2013 at 23:15

1 Answer 1

4

I had the same problem and I solved it by change the

curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

to be

curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.