简体   繁体   English

CURL NTML身份验证从命令行运行,但不适用于php脚本

[英]CURL NTML authentication is working from command line but not working with php script

I need to call a .net web service. 我需要调用.net Web服务。 This web service requires NTLM authentication. 此Web服务需要NTLM身份验证。 For that, I wrote some code with NTLM authentication. 为此,我编写了一些具有NTLM身份验证的代码。 And I am trying to connect using curl with NTLM authentication. 我正在尝试使用curl与NTLM身份验证进行连接。 But from php script I am getting 401 error. 但是从PHP脚本我得到401错误。 I tried with different header content (xml and html). 我尝试使用不同的标头内容(xml和html)。 Please help. 请帮忙。

Below is the command line which is working. 下面是正在运行的命令行。

curl http://qtskofaxweb01.etch.com/TotalAgility/Services/Sdk/JobService.svc?wsdl -v --ntlm --negotiate -u kofax:Jagadish6^

Below is my PHP script which is not working 下面是我的PHP脚本不起作用

$path = 'http://qtskofaxweb01.etch.com/TotalAgility/Services/Sdk/JobService.svc?wsdl';
$user = 'kofax';
$password = 'Jagadish6^';

$ch = curl_init($path);

$headers = array();
$headers[] = 'Accept: text/xml';
$headers[] = 'Content-Type: text/xml';

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_USERPWD, $user.':'.$password);

$result = curl_exec($ch);

print_r(curl_getinfo($ch));
echo curl_error($ch);
curl_close($ch);
var_dump($result);

Out put is given below 输出如下

Array
(
    [url] => http://qtskofaxweb01.etch.com/TotalAgility/Services/Sdk/JobService.svc?wsdl
    [content_type] => text/html
    [http_code] => 401
    [header_size] => 657
    [request_size] => 546
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 1
    [total_time] => 0.003738
    [namelookup_time] => 1.4E-5
    [connect_time] => 1.5E-5
    [pretransfer_time] => 1.7E-5
    [size_upload] => 0
    [size_download] => 1293
    [speed_download] => 345906
    [speed_upload] => 0
    [download_content_length] => 1293
    [upload_content_length] => 0
    [starttransfer_time] => 0.002228
    [redirect_time] => 0.001484
    [certinfo] => Array
        (
        )

[primary_ip] => 10.10.3.40
[redirect_url] => 

)

string '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>401 - Unauthorized: Access is denied due to invalid credentials.</title> <style type="text/css"> <!-- body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;} fieldset{padding:0 15px 10px 15px;} h1{font-size:2.4em;mar'... (length=1293)

please try it.. 请尝试一下。

$url="http://qtskofaxweb01.etch.com/TotalAgility/Services/Sdk/JobService.svc?wsdl";

    $user = 'kofax';
    $password = 'Jagadish6^';

    $parameters=array();

    class Emp {
      public $user  = "";
      public $password   = "";
   }
   $e = new Emp();
   $e->user = $user ;
   $e->password   = $password ;

    $parameters['user']=$e;
    $parameters=json_encode($parameters);

    $ch = curl_init();  

    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Accept: application/json',
    'Content-type: application/x-www-form-urlencoded'
    ));
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $output=curl_exec($ch);

    if($output === false)
    {
        echo "Error Number:".curl_errno($ch)."<br>";
        echo "Error String:".curl_error($ch);
    }
    curl_close($ch);

    $obj = json_decode($output, TRUE);

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

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