簡體   English   中英

使用PHP從ASP頁面獲取數據

[英]Get data from a ASP page using Php

我正在嘗試從下面的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復制到代碼中?

嘗試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM