我撞墙了,似乎无法在堆栈(或其他任何地方)找到合适的答案。我在通过PHP获取cURL请求时遇到问题,无法正确授权。
通过命令行使用cURL 7.57.0的以下请求有效:
curl --negotiate -u MYDOMAIN\myuser:mypass http://myip:myport/mywebservice.svc
当我使用PHP 5.6.4(在Windows上运行)和cURL v7.39.0尝试下面的代码时出现401.2错误:
<?php
//Set vars
$url = "http://myip:myport/mywebservice.svc"; // asmx URL of WSDL
$un = "myuser"; // username
$password = "mypass"; // password
$domain = "MYDOMAIN\\"; // domain
//Set Header Array
$headers = array(
'Method: GET',
'Content-Type: text/xml;charset=UTF-8',
'User-Agent: PHP-SOAP-CURL',
"SOAPAction: urn:MyService");
//Create, Send and Output cURL Request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NEGOTIATE);
curl_setopt($ch, CURLOPT_USERPWD, $domain . $un.":".$password);
$response = curl_exec($ch);
echo $response;
?>
以下是PHP CURL设置:
cURL support => enabled
cURL Information => 7.39.0
Age => 3
**Features**
AsynchDNS => Yes
CharConv => No
Debug => No
GSS-Negotiate => No
IDN => Yes
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
NTLMWB => No
SPNEGO => Yes
SSL => Yes
SSPI => Yes
TLS-SRP => No
Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, pop3, pop3s, rtsp, scp, sftp, smtp, smtps, telnet, tftp
Host => i386-pc-win32
SSL Version OpenSSL/1.0.1i
ZLib Version => 1.2.7.3
libSSH Version => libssh2/1.4.3
为了它的价值,我正在尝试使用Windows身份验证与#34; Negotiate&#34;提供商
有没有人有任何想法我做错了什么?这是PHP v7.39的CURL 7.57和curlib之间的区别吗?
还有其他想法吗?
提前非常感谢! 丹
*****************编辑********************
此时,我最好的猜测是PHP curlib中的CURLAUTH_NEGOTIATE与我在下载的cURL库中的--negotiate并通过CMD线分别运行时没有做同样的事情!话虽如此,我想我会开始新的,更精确和明确陈述的问题。感谢所有评论的人。