使用Php从ASP页面获取数据
我正在尝试从下面的url获取数据,但没有成功。我已经阅读了很多关于Viewstate的内容,但是我没有成功地使其工作。每当我执行此操作时,我都没有得到任何数据,但我没有得到任何错误 http://agmarkweb.dacnet.nic.in/SA_Pri_MonthRep.aspx';使用Php从ASP页面获取数据,php,curl,asp-classic,Php,Curl,Asp Classic,我正在尝试从下面的url获取数据,但没有成功。我已经阅读了很多关于Viewstate的内容,但是我没有成功地使其工作。每当我执行此操作时,我都没有得到任何数据,但我没有得到任何错误 http://agmarkweb.dacnet.nic.in/SA_Pri_MonthRep.aspx'; $fields = array( 'Year_list'=>urlencode("2013"), 'Month_list'=>url
$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);
我读了很多关于视图状态的书,但是在这种情况下应该怎么做呢?是否应将Viewstate复制到代码中?尝试以下操作:
$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);