我正在尝试从下面的url获取数据但是我没有成功。我已经阅读了很多关于Viewstate但我没有成功地让它工作..每当我执行这个我没有数据但我没有得到任何错误。
http://agmarkweb.dacnet.nic.in/SA_Pri_MonthRep.aspx';
$fields = array(
'Year_list'=>urlencode("2013"),
'Month_list'=>urlencode("2"),
'Commodity_list'=>urlencode("40"),
'__EVENTTARGET'=>(""),
'__EVENTARGUMENT'=>(""),
'__LASTFOCUS'=>(""),
'__VIEWSTATE'=>(""));
//url-ify the data for the POST
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_setopt($ch, CURLOPT_HEADER, CURLOPT_ENCODING);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U;Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
//execute post
$result = curl_exec($ch);
echo $result;
//close connection
curl_close($ch);
我读了很多关于View状态但在这种情况下应该做些什么?我是否应该将Viewstate复制到我的代码中?
答案 0 :(得分:1)
试试这个:
$fields = array(
'Year_list'=>2013,
'Month_list'=> 2,
'Commodity_list'=>40,
'__EVENTTARGET'=>'',
'__EVENTARGUMENT'=>'',
'__LASTFOCUS'=>'',
'__VIEWSTATE'=>''
);
//open connection
$ch = curl_init();
$url = 'http://agmarkweb.dacnet.nic.in/SA_Pri_MonthRep.aspx';
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_setopt($ch, CURLOPT_HEADER, CURLOPT_ENCODING);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U;Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
//execute post
$result = curl_exec($ch);
echo $result;
//close connection
curl_close($ch);