我正在尝试使用PHP curl登录.aspx页面。现在我抓住登录页面获取VIEWSTATE并组成正确的url来发出请求,之后还有一个其他curl请求发布字段并登录。这个curl调用返回404错误。我已经尝试用其他卷曲制作其他卷曲请求,但它会重定向到登录页面。 我哪里错了?
include('../dom/simple_html_dom.php');
$ckfile = tempnam ("/tmp", "CURLCOOKIE");
$url = 'http://www.EXAMPLE.com/Shop/Login.aspx';
//FIRST CALL TO GRAB THE VIEWSTATE VALUE
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // Accepts all CAs
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); //Uses cookies from the temp file
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Tells cURL to follow redirects
$output = curl_exec($ch);
$html = str_get_html($output);
//GRABBING THE VALUES
$evttarget = 'LogonBox%24btnLogin';
$evtarg = '';
$viewstate = urlencode($html->find('input#__VIEWSTATE')[0]->value);
$viewgen = urlencode($html->find('input#__VIEWSTATEGENERATOR')[0]->value);
$username = 'MYUSERNAME';
$password = 'MYPASSWORD';
//COMPOSING THE URL
$url = 'http://www.EXAMPLE.com/Shop/Login.aspx?__EVENTTARGET='.$evttarget.'&__EVENTARGUMENT='.$evtarg.'&__VIEWSTATE='.$viewstate.'&__VIEWSTATEGENERATOR='.$viewgen.'&LogonBox%24txtUsername='.$username.'&LogonBox%24txtPassword='.$password;
//LOGIN REQUEST
$ch = curl_init();
print $url;
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // Accepts all CAs
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile); //Uses cookies from the temp file
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Tells cURL to follow redirects
$output = curl_exec($ch);
THIS RETURNS A 404 ERROR