【发布时间】:2015-12-28 18:30:58
【问题描述】:
我快疯了!我阅读了一千篇关于 Curl PHP for SSL Auth 的 400 Bad Request 错误的帖子,但我从未找到详尽的答案。
这就是我的 sn-p:
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。 谢谢你
【问题讨论】:
-
你试过设置
CURLOPT_USERAGENT吗?也许服务器需要知道它不是请求数据的机器人或爬虫? -
是的,我试过这个: curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/ 2.0.0.13');但在此之后,我收到 401 未授权(没有意义,用户名和密码是正确的)
标签: php authentication ssl curl