簡體   English   中英

使用Curl Php SSL身份驗證的400錯誤請求

[英]400 Bad Request with Curl Php SSL Authentication

我快瘋了! 我讀過一千篇關於用SSL身份驗證使用Curl PHP的關於400 Bad Request錯誤的文章,但我從未找到詳盡的答案。

這是我的代碼段:

ini_set('display_errors','On');
error_reporting(E_ALL);

$username=''; // To Set
$password=''; //To Set

// CODICE DAVIDE

 $ch = curl_init();//
 curl_setopt($ch, CURLOPT_URL, 'https://webstudenti.unica.it/esse3/Home.do');
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_HEADER, true);
 curl_setopt($ch, CURLOPT_COOKIESESSION, true);
 curl_setopt($ch, CURLOPT_VERBOSE, true);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
 $response = curl_exec($ch);

 preg_match("/Set-cookie: (.*)\n/iU", $response, $matches);
 $cookie = trim(substr($matches[1], strpos($matches[1],':')));

 $url = "https://webstudenti.unica.it/esse3/auth/Logon.do";
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
 curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);
 curl_setopt($ch, CURLOPT_HEADER, true);
 curl_setopt($ch, CURLOPT_COOKIE, $cookie);
 curl_setopt($ch, CURLOPT_COOKIESESSION, true);
 curl_setopt($ch, CURLOPT_VERBOSE, true);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

 $response = curl_exec($ch);
 curl_close($ch);

 var_dump($response);

會是什么 我真的找不到解決方案。 我正在使用Windows Server和Microsoft Azure,PHP版本:5.4。 謝謝

我可以使用下面的代碼段成功連接。 我為第二個請求添加了新變量$curl ,而不是再次使用$ch

由於未設置用戶/密碼,因此我收到HTTP/1.1 401 Unauthorized 嘗試使用設置的用戶名/密碼,讓我知道您找到了什么。

$curl = curl_init();
$url = "https://webstudenti.unica.it/esse3/auth/Logon.do";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);
curl_setopt($curl, CURLOPT_USERPWD, $username.':'.$password);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
// curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // Might need this, but I was able to verify it works without
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');

$response = curl_exec($curl);
curl_close($curl);
var_dump($response);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM