简体   繁体   中英

Get data from a ASP page using Php

I am trying to get data from the below url But I have been unsuccessful.I have read a lot about Viewstate but I am unsuccessful in getting this to work..Whenever I execute this I get no data but I am not getting any errors.

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);

I read a lot about View state but what should be done in this case? Whether I should just copy the Viewstate into my code?

try this:

$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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM