简体   繁体   English

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

[英]CURL - This request requires HTTP authentication

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. 我确实上传它作为AppFog应用程序,它工作正常。 The issue is when I try to run the same code on Windows Server 2008 IIS7 or on WAMP. 问题是当我尝试在Windows Server 2008 IIS7或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: 似乎我没有发送凭据,但'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

Any ideas what might be the issue? 任何想法可能是什么问题? Thanks. 谢谢。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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