我有一段在 .NET (4.0) 中完美运行的代码
代码#
string URI = "http://www.indianrail.gov.in/cgi_bin/inet_pnrstat_cgi.cgi";
string Parameters = Uri.EscapeUriString("lccp_pnrno1=8561180607&submitpnr=Get Status");
System.Net.HttpWebRequest req = (HttpWebRequest)System.Net.WebRequest.Create(URI);
//HTTP POST Headers
req.ContentType = "application/x-www-form-urlencoded";
req.Host = "www.indianrail.gov.in";
//You can use your own user-agent.
req.UserAgent = "Mozilla/5.0 (compatible; MSIE 7.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0) DELL;Venue Pro";
req.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us,en;q=0.5");
req.Headers.Add(HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
req.KeepAlive = true;
req.Referer = "http://www.indianrail.gov.in/pnr_stat.html";
req.Accept = "text/plain";
req.Method = "POST";
//Byte size calculation before sending request.
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
System.Net.WebResponse resp = req.GetResponse();
var request_status = ((HttpWebResponse)resp).StatusDescription;
if (resp == null) return;
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
Console.WriteLine(sr.ReadToEnd());
Console.ReadLine();
我只是不知道在 Win Store 应用程序中写什么
到目前为止,我已经到了我必须使用的类(或者可能不是)
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Host", "www.indianrail.gov.in");
但是其他值呢?有一些标题我们可以在其中添加一些数据,有些需要直接添加到集合(DefaultHeaders)中......
是否有相同的用法和说明文档
在这个方向上的任何帮助都会很棒:)