繁体   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