簡體   English   中英

curl登錄Https asp頁面

[英]curl login on Https asp page

我正在嘗試使用來自PHP的https登錄頁面登錄.asp站點。 我無法登錄該網站。 似乎沒有生成Cookie,查看狀態等,也沒有將這些參數排除在外。 表單字段似乎正確填充(我可以實際看到登錄名),但是我不確定密碼字段是密碼類型,但是我認為那里沒有問題,其拼寫正確等。

我已經嘗試了所有相關的帖子,包括http://www.mishainthecloud.com/2009/12/screen-scraping-aspnet-application-in.html?showComment=1368565341638#c9104469935977149435

我的代碼在下面,並在最終調用中返回“未找到”(我認為是錯誤代碼7。)。 前兩個呼叫沒有卷曲錯誤。

有人能幫忙嗎?

$ckfile = tempnam ("/tmp", "CURLCOOKIE"); 

// URL to login page 
$url = "https://secure2.clubwise.com/glenview/memberlogin.asp"; 

// Get Login page and its cookies/ viewstate , etc
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $url); 
//curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile); // no cookie stored 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$output = curl_exec($ch); 
//print(esc_html($output));

$viewstate = regexExtract($output,$regexViewstate,$regs,1);
$eventval = regexExtract($output, $regexEventVal,$regs,1);

// rebuild post info -- view state and eventvalidate empty! cant find on page
$fields_string =  
'__VIEWSTATE='.rawurlencode($viewstate).
'&__EVENTVALIDATION='.rawurlencode($eventval).
'&login='.urlencode('xxx@xxx.com'). 
'&password='.urlencode('xxxx').
'&submit='.urlencode('Sign in').
'&redirect='; 

echo $fields_string;

// Post login form -- password field ok?
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, 5); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Tells cURL to follow redirects 
$outputb = curl_exec($ch); 
print curl_error;
//var_dump($outputb);


$url = "https://secure2.clubwise.com/glenview/bookclass.asp"; 
$ch = curl_init();  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); 
//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$outputc = curl_exec($ch); 
print curl_error;
var_dump($outputc);

標頭信息:

//$header= array(
//'HTTP/1.1 200 OK',
//'Date: Mon, 09 Jun 2014 00:55:17',
//'GMT Server: Microsoft-IIS/6.0',
//'X-Powered-By: ASP.NET',
//'Content-Length: 21035',
//'Content-Type: text/html',
//'Set-Cookie: ASPSESSIONIDCCSBSTDC=IHJBDOOBIDMJDDOFLAOOBENL; path=/',
//'Cache-control: private'

//);

解決方案:導致此中斷的每個操作都是curl_init()。 Viewstate,不需要標題。

$ourFileName = get_stylesheet_directory()."/cookieFile.txt";
$ckfile = $ourFileName; 

// URL to login page 
$url = "https://secure2.clubwise.com/glenview/memberlogin.asp"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile); // Stores cookies in the temp file 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);

$output = curl_exec($ch); 

//Cookie obtained, login 
$fields_string =  
'&redirect='.
'&login='.urlencode('vvv@xxx.com'). 
'&password='.urlencode('xxx').
'&submit='.urlencode('"Sign in"' )
; 

//cookie in the header + header not required
/*
$cookielines =file($ckfile);
foreach($cookielines as $row) {
if($row[0] != '#') {
    $cookie=$row;
    }
}


$header= array( // not needed at moment

'HTTP/1.1 200 OK',
'Date: Mon, 09 Jun 2014 00:55:17',
'GMT Server: Microsoft-IIS/6.0',
'X-Powered-By: ASP.NET',
'Content-Length: 21035',
'Content-Type: text/html',
'Set-Cookie: $cookie; path=/',
'Cache-control: private'

);

*/

$url = "https://secure2.clubwise.com/glenview/memberlogin.asp"; 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, 4); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); //Uses cookies from the temp file 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Tells cURL to follow redirects 
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_ENCODING,""); 
curl_setopt($ch, CURLOPT_REFERER,"https://secure2.clubwise.com/glenview/memberlogin.asp");
$outputb = curl_exec($ch); 

$err = curl_errno ( $ch ); echo "<br>error=".$err;
$errmsg = curl_error ( $ch ); echo "<br>errmsg=".$errmsg;
$header = curl_getinfo ( $ch ); echo "<br>header="; var_dump($header);
$httpCode = curl_getinfo ( $ch, CURLINFO_HTTP_CODE ); echo "<br>httpcode=".$httpCode;

print curl_error;

//現在,只要包含每個呼叫的Cookie,您就應該能夠訪問密碼限制區域內的任何頁面:

$url = "https://secure2.clubwise.com/glenview/bookclass.asp?Mode=Area&RecId=67"; 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Accepts all CAs 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 0 );
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); //Uses cookies from the temp file 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$outputc = curl_exec($ch); 
print curl_error;

var_dump($outputc);

請再次檢查cookie存儲在第一頁上。 為會話cookie設置CURLOPT_COOKIEFILECURLOPT_COOKIEJAR ,而不重新初始化或關閉curl以保存會話。 設置CURLOPT_REFERER ,某些站點將其檢查為登錄頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM