[英]curl .net https page login problem 500 Internal Server Error
当我尝试使用curl登录到页面时,出现500 Internal Server Error 。 页面位于https上。
这是登录功能:
function login ($login, $pass) {
$loginURL = "https://bitomat.pl/Account/LogOn";
$loginPage = $this->curl->getPage($loginURL);
$numStart = strpos(htmlentities($loginPage['content']), "type="hidden" value="");
$numEnd = strpos(htmlentities($loginPage['content']), "<fieldset>");
$verNum = substr(htmlentities($loginPage['content']), $numStart+36, 64);
echo $numStart." - ".$numEnd." - ".$verNum."<br>";
$page = $this->curl->post($loginURL, "__RequestVerificationToken=".urlencode($verNum)."&UserName=$login&Password=".urlencode($pass)."&RememberMe=false");
echo nl2br(htmlentities($page['content']));
}
作为回应,我得到:
HTTP/1.1 500 Internal Server Error
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.0
X-AspNetMvc-Version: 2.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sat, 25 Jun 2011 16:32:18 GMT
Content-Length: 3974
CUrl发布功能:
function post($url, $params) {
$rnd = rand(0, 10000000000);
$options = array(
CURLOPT_COOKIESESSION => true,
CURLOPT_COOKIEFILE => "cookie/cookieBitomat",// . $rnd,
CURLOPT_COOKIEJAR => "cookie/cookieBitomat",// . $rnd,
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => true, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $params,
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 60, // timeout on connect
CURLOPT_TIMEOUT => 60, // timeout on response
CURLOPT_MAXREDIRS => 20, // stop after 10 redirects
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_VERBOSE => TRUE,
CURLOPT_HTTPHEADER => array("Content-Type: application/x-www-form-urlencoded",
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Host: bitomat.pl",
"Accept-Language: pl,en-us;q=0.7,en;q=0.3",
"Accept-Encoding: gzip, deflate",
"Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7",
"Keep-Alive: 115",
"Connection: keep-alive",
"Referer: https://bitomat.pl/Account/LogOn"
)
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch);
$header = curl_getinfo($ch);
curl_close($ch);
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}
通常,在这种情况下您会得到500,因为在这种情况下您的HTTP请求与浏览器所执行的HTTP请求有所不同,并且服务器端脚本会对此有所假设。
确保检查“实时”请求并尽可能地模仿。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.