拒绝访问:使用cURL php来获取页面内容

<?PHP

//set POST variables
$url = 'http://cbseresults.nic.in/class12/cbse122014_total.asp';

$fields = array(
                        'regno' => '6600001',
                        'B1' => 'Submit',
                        'FrontPage_Form1' => 'Submit',



                );

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string[]= $key.'='.$value;}
$fields_items = implode ('&', $fields_string);


//open connection
$ch = curl_init();
//fname%3Dasdf%26lname%3Dsdafasdf%26lolz%3DSubmit
//set the url, number of POST vars, POST data

curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_items);
//curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
//curl_setopt($ch, CURLOPT_COOKIEFILE,  'cookie.txt');
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36');

//execute post
$result = curl_exec($ch);

echo "<br>Field Item= "."<br>";
echo $result."=Result"."</br>";


echo curl_errno($ch) . '<br>' . 
            curl_error($ch);
//close connection
curl_close($ch);

?>

上面给出的代码将发布请求发送到链接http://cbseresults.nic.in/class12/cbse122014_total.asp,它应显示给定的roll-number(regno)的结果,但显示访问被拒绝.
代码位于http://computerinfo.in/school/test2.php.
请告诉我问题出在哪里或如何解决

解决方法:

删除额外的参数

‘FrontPage_Form1’ => ‘Submit’,

从$fields数组中获取有效请求.您的数组应为:

$fields = array(
   'regno' => '6600001',
   'B1' => 'Submit'
);

您还需要指定引荐来源网址,即:

curl_setopt($ch, CURLOPT_REFERER, 'http://cbseresults.nic.in/class12/cbse122014_total.htm');

注意:

通常,我建议您在尝试之前先咨询他们,因为似乎他们在极力地拒绝像您这样的外部请求,您可能因此违反了法律或免责声明.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...