[英]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.