c# – 使用带WinRT的HttpClient类

c# – 使用带WinRT的HttpClient类,第1张

概述我有一段在.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"); 我有一段在.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,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)…

是否有相关的使用和描述的文档

在这方面的任何帮助将是伟大的:)

解决方法 任何方式都要感谢社区的帮助….一些阅读让我找到了解决方案
string URI = "http://www.indianrail.gov.in/cgi_bin/inet_pnrstat_cgi.cgi";            string Parameters = Uri.EscapeUriString("lccp_pnrno1=8561180604&submitpnr=Get Status");            httpClIEnt clIEnt = new httpClIEnt();            httpRequestMessage request = new httpRequestMessage(httpMethod.Post,URI);            request.headers.Accept.Add(new MediaTypeWithQualityheaderValue("text/plain"));            request.headers.AcceptCharset.Add(new StringWithQualityheaderValue("utf-8",0.7));            request.headers.AcceptLanguage.Add(new StringWithQualityheaderValue("en-us",0.5));            request.Content = new StreamContent(new MemoryStream(System.Text.EnCoding.UTF8.GetBytes(Parameters)));            request.Content.headers.Add("Content-Type","application/x-www-form-urlencoded");            request.headers.Host = "www.indianrail.gov.in";            request.headers.UserAgent.Add(new ProductInfoheaderValue("Mozilla","5.0"));            request.headers.Referrer = new Uri("http://www.indianrail.gov.in/pnr_stat.HTML");            var result = await clIEnt.SendAsync(request);            var content = await result.Content.ReadAsstringAsync();

这将返回我想要的结果

谢谢你的方式

总结

以上是内存溢出为你收集整理的c# – 使用带WinRT的HttpClient类全部内容,希望文章能够帮你解决c# – 使用带WinRT的HttpClient类所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1262361.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存