簡體   English   中英

CURL NTML身份驗證從命令行運行,但不適用於php腳本

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

我需要調用.net Web服務。 此Web服務需要NTLM身份驗證。 為此,我編寫了一些具有NTLM身份驗證的代碼。 我正在嘗試使用curl與NTLM身份驗證進行連接。 但是從PHP腳本我得到401錯誤。 我嘗試使用不同的標頭內容(xml和html)。 請幫忙。

下面是正在運行的命令行。

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

下面是我的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);

輸出如下

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)

請嘗試一下。

$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