curl .net https页面登录问题500内部服务器错误

问题描述

| 当我尝试使用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\",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请求与浏览器在这种情况下所做的请求有所不同,并且服务器端脚本会对此有所假设。 确保检查“实时”请求并尽可能地模仿。