CURL - 此请求需要HTTP身份验证

时间:2013-04-26 21:49:47

标签: php http curl

我有以下代码:

$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);

我确实将其上传为AppFog应用程序并且工作正常。 问题是当我尝试在Windows Server 2008 IIS7或WAMP上运行相同的代码时。

我从服务器收到以下消息:

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

似乎我没有发送凭据,但'request_header'具有以下值:

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

任何想法可能是什么问题?感谢。

1 个答案:

答案 0 :(得分:4)

我遇到了同样的问题,我通过更改

解决了这个问题
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);