gpt4 book ai didi

php - 拒绝访问 : Using cURL php to fetch the content of a page

转载 作者:搜寻专家 更新时间:2023-10-31 20:39:25 24 4
gpt4 key购买 nike

<?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 ) 但它显示 access denied。代码位于 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');

注意事项:

一般来说,我建议您在尝试之前先咨询他们,因为他们似乎没有很好地尝试禁止像您这样的外部请求,您可能会因此而违反法律或使用免责声明。

关于php - 拒绝访问 : Using cURL php to fetch the content of a page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26812080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com