2012-05-12 36 views
0

我試圖在「http://www.indianrail.gov.in/cgi_bin/inet_srcdest_cgi_time.cgi」使用asp.net發佈數據的響應與C#。問題是我使用的代碼不能發佈多個數據。此代碼已經正常工作時,我曾在「http://www.indianrail.gov.in/cgi_bin/inet_trnnum_cgi.cgi」然而,當我試圖發佈一個以上的數據,這是不工作剛剛發佈的一個數據。另外每個輸入數據都有一個隱藏字段,所以我該怎麼處理這個隱藏字段。在asp.net發佈一個以上的數據用C#和取回

ASCIIEncoding encoding = new ASCIIEncoding(); 
    string postData = "lccp_src_stncode=" + src; 
    postData += ("&lccp_dstn_stncode=" + des); 
    byte[] data = encoding.GetBytes(postData); 
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://www.indianrail.gov.in/cgi_bin/inet_srcdest_cgi_time.cgi"); 
    myRequest.Method = "POST"; 
    myRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0"; 
    myRequest.ContentType = "application/x-www-form-urlencoded"; 
    myRequest.ContentLength = data.Length; 
    Stream newStream = myRequest.GetRequestStream(); 
    // Send the data. 
    newStream.Write(data, 0, data.Length); 
    newStream.Close(); 

    HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse(); 

    //Get the stream containing content returned by the server. 
    newStream = response.GetResponseStream(); 

    // Open the stream using a StreamReader for easy access. 
    StreamReader reader = new StreamReader(newStream,Encoding.UTF8); 

    // Read the content. 
    string responseFromServer = reader.ReadToEnd(); 

    File.WriteAllText(@"C:\Users\Zohaib\Documents\Visual Studio 2010\WebSites\WebSite4\App_Data\data.txt", responseFromServer); 
    // Clean up the streams. 
    reader.Close(); 
    newStream.Close(); 
    response.Close(); 

回答

0

在POST中,您只需提供一個數據流。該流是包含「兩個」的東西,你只需序列化兩個流。在你的情況,如果你想發送更多的領主一個查詢字符串參數,只需添加到您調用GetBytes會

前的字符串
相關問題