我疯了!我阅读了一篇关于使用Curl PHP进行SSL身份验证的400个错误请求错误的帖子,但我从未找到详尽的答案。
所以这是我的片段:
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);
它能是什么?我真的找不到解决方案。我正在使用带有Microsoft Azure的Windows Server,Php版本:5.4。 三江源
答案 0 :(得分:0)
我能够使用下面的代码段成功连接。我为第二个请求添加了新变量$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);