PHP libcurl VS中的CURLAUTH_NEGOTIATE之间的区别. -在cURL 7.57.0中协商 [英] Difference between CURLAUTH_NEGOTIATE in PHP libcurl VS. --negotiate in cURL 7.57.0

查看:159
本文介绍了PHP libcurl VS中的CURLAUTH_NEGOTIATE之间的区别. -在cURL 7.57.0中协商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能阐明PHP libcurl中的CURLAUTH_NEGOTIATE(在Windows上使用libcurl v7.39.0运行的PHP 5.6.4)和cURL 7.57.0中的--negotiate之间的区别?

Can anyone shed some light on the different between CURLAUTH_NEGOTIATE in PHP libcurl (PHP 5.6.4 running on Windows with libcurl v7.39.0) and --negotiate in cURL 7.57.0?

以下通过命令行使用cURL 7.57.0的请求有效:

curl --negotiate -u MYDOMAIN\myuser:mypass  http://myip:myport/mywebservice.svc

当我使用PHP 5.6.4(在Windows上运行)和libcurl v7.39.0尝试以下代码时,远程Web服务器返回401.2错误:

<?php
//Set vars
$url = "http://myip:myport/mywebservice.svc"; // asmx URL of WSDL
$un = "myuser";  //  username
$password = "mypass"; // password
$domain = "MYDOMAIN\\"; // domain

//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_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

任何见解都将不胜感激!谢谢〜丹

Any insights are greatly appreciated! Thanks ~Dan

推荐答案

要解决上述问题,我只是绕过PHP使用的libcurl.我从 https://curl.haxx.se/download.html(我们的服务器位于Windows上,仅供参考),然后将其放在可访问的目录中.

To work around the problem stated above, I am just bypassing the libcurl used by PHP. I downloaded the latest version of cURL from https://curl.haxx.se/download.html (Our server is on windows, just FYI) and put it in an accessible directory.

然后简单地编写以下代码:

Then simply wrote the following code:

<?php

//Set vars
$url = "http://<my_host_ip_or_domain>:<my_host_post_if_needed>/<my_path_etc>";
$userName = "DOMAIN\username";
$password = "password";
$filePath = "myxmlfile.xml";
$contentLength = strlen(file_get_contents($filePath));

//Set any curl args (other than headers) you wish - per https://curl.haxx.se/docs/manpage.html (These are the ones I needed to solve my particular authentication problem)
$curlSettings = array();
$curlSettings["--negotiate"] = '';
$curlSettings["-u"] = $userName .':'.  $password;
$curlSettings["--http1.1"] = '';
$curlSettings["--location-trusted"] = '';
$curlSettings["--post301"] = '';
$curlSettings["--data"] = '@"'. $filePath .'"';


//Set any cURL headers you want
$curlHeaders = array(
    'Content-Type: text/xml; charset=utf-8',
    'Content-Length: '. $contentLength,
    'SOAPAction: http://tempuri.org/blahblahblah',
    'Host: <my_host_ip>:<my_host_port>'
);

//Call the function
$curlResp = curlRequest($url, $curlSettings, $curlHeaders);

//Output the result
echo '<pre>';
print_r($curlResp);
echo '</pre>';


//Handle cURL Request
function curlRequest($url,$args,$headers)
{   
    /*
        Note: This needs to be the full path to CURL on server or you can set it to run as a windows cmd (as I have), 
        by following the instructions outlined by Michiel van Oosterhout in the following post: 
        https://stackoverflow.com/questions/9507353/how-do-i-install-set-up-and-use-curl-on-windows 
    */
    $strCurl = "curl";

    //Add Args / Setting to cURL request
    foreach ($args as $key => $val)
    {
        $strCurl .= " ". $key ." ". $val;
    }

    //Add headers to cURL request
    foreach ($headers as $h)
    {
        $strCurl .= ' --header "'. $h .'"';
    }

    //Set the URL
    $strCurl .= " ". $url;

    //Execute the curl request
    exec($strCurl, $resp);

    //Return an array of the response
    return $resp;
}

?>

像魅力一样工作!

这篇关于PHP libcurl VS中的CURLAUTH_NEGOTIATE之间的区别. -在cURL 7.57.0中协商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆