我已经为这项任务苦苦挣扎了将近三天,我想我缺少一些基本的 cURL 技能。
我开始:
在 IE 的 F12 中,我在第一页看到 2 个 POST:(我注意到第一个得到 302 应该是重定向,而使用 cURL 我只得到 200)
填写验证码:
在第二页(验证码之后):
交通:
这是我的代码(我无法继续使用它,因为它不适用于早期阶段):
我构建了一个特殊的表单,该表单使用(使用 cURL)提交到我自己的页面,而该页面GET
又访问了该网站:
$id=$_GET['id']; // getting the biznumber
$humanCode=$_GET['nobot'];
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, "https://www.*******.******.***");
// setting some https to be able to access the website from my local computer.
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_CAINFO, "c:/xampp/htdocs/CAcerts/curl-ca-bundle.crt");
// I know the values for the ASPX vars like __EVENTTARGET, __EVENTARGUMENT, __VIEWSTATE are arbitrary now. I need to take care of that but I don't yet know how.
$postarr= array (
"__EVENTTARGET"=>"",
"__VIEWSTATE=" =>"%2FwEPDwULLTEzMzI2OTg4NDYPZBYCZg9kFgQCBA8PZBYCHgdvbmNsaWNrBQxnb1RvTWl2emFrKClkAgYPD2QWAh8ABQxnb1RvTWl2emFrKClkZM6iZZ0Qaf2CpfXoJJdZ0IqaWsDO",
"__EVENTARGUMENT=" =>"",
"__EVENTVALIDATION" =>"%2FwEWBQKgysLGCwL2r7SGDQLh4ri%2BAwLWws7NDwLWwpLPD%2F1HuCAFYzs2seaziWbYEXjDfigP",
"hidUrlFileIshurim"=>"https%3A%2F,
"cod"=>"3322"
);
$fields_string='';
foreach($postarr as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
curl_setopt($curl, CURLOPT_POST ,1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt ($curl, CURLOPT_USERAGENT, "User-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; MAAU)");
// I made a cookie file and it seems to work
$cookiefile = "d:/cookie.txt";
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($curl, CURLOPT_FRESH_CONNECT , 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($curl, CURLOPT_HEADER ,1); // DO NOT RETURN HTTP HEADERS
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$temp=curl_exec($curl);
$info = curl_getinfo($curl);
$html = mb_convert_encoding($temp, 'HTML-ENTITIES', 'utf-8');
echo "ERRCODE: ".curl_error($curl);
echo '<br /><br />';
echo "INFO : ";
print_r($info);
echo '<br /><br />';
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
echo "CODE: ".$httpcode;
echo '<br /><br />';
echo "CODE: ".$httpcode;
echo '<br /><br />';
echo "VARS: ".$vars;
echo '<br /><br />';
//echo $html;
curl_setopt ($curl, CURLOPT_URL, "https://www.*******.******.***");
curl_setopt($curl, CURLOPT_FRESH_CONNECT , 0);
echo "<br /><br /><b>2nd</b><br /><br />";
$temp=curl_exec($curl);
$info = curl_getinfo($curl);
$html = mb_convert_encoding($temp, 'HTML-ENTITIES', 'utf-8');
echo "ERRCODE: ".curl_error($curl);
echo '<br /><br />';
echo "INFO : ";
print_r($info);
echo '<br /><br />';
echo $html;
甚至无法开始工作。它从返回 200 OK 而不是 302 开始,有时我也会得到 500。
我知道 ASPX 变量实际上可能至关重要,但如果我的浏览器可以制作这些变量并将它们发送到服务器,cURL 不能做同样的事情吗?
谢谢你的帮助 !!