我正在尝试使用带有 C# 的 asp.net 在“http://www.indianrail.gov.in/cgi_bin/inet_srcdest_cgi_time.cgi”上发布数据。问题是我使用的代码无法发布多个数据。当我在“http://www.indianrail.gov.in/cgi_bin/inet_trnnum_cgi.cgi”上仅发布一个数据时,此代码可以正常工作,但是当我尝试发布多个数据时,这不起作用。每个输入数据还附加一个隐藏字段,那么我与该隐藏字段有什么关系。
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();