GET:在 C# 中获取 http 响应
GET : Getting an http response in C#
WebRequest req = WebRequest.Create("[URL here]");
WebResponse rep = req.GetResponse();
我想深入了解 GetResponse 方法的相关性,它现在似乎已弃用。
我一起破解的另一种方法可以完成工作。
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(String.Format("http://mywebservicehere/dostuff?url=https://www.website.com"));
request.Method = "GET";
using (var response = (HttpWebResponse) (await Task<WebResponse>.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null)))
{
var encoding = ASCIIEncoding.ASCII;
StreamReader reader = new StreamReader(response.GetResponseStream(), encoding);
}
想知道其他人可能使用过的替代方法吗?感谢您的帮助!
I wanted some insights into the relevance of the GetResponse method,
it appears to deprecated now.
它没有被弃用,在 UWP 的 .NET 中,它是一种异步方法。
WebRequest req = WebRequest.Create("[URL here]");
WebResponse rep = await req.GetResponseAsync();
Wanted to know of any alternative methods others may have used?
除了 WebRequest class,Windows Runtime Platform 中还有另外 2 个 HttpClient classes,您可以使用它来获取 http 响应。
var client1 = new System.Net.Http.HttpClient();
var client2 = new Windows.Web.Http.HttpClient();
System.Net.Http.HttpClient 在 .NET for UWP 中。
Windows.Web.Http.HttpClient 在 Windows 运行时。
WebRequest req = WebRequest.Create("[URL here]");
WebResponse rep = req.GetResponse();
我想深入了解 GetResponse 方法的相关性,它现在似乎已弃用。
我一起破解的另一种方法可以完成工作。
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(String.Format("http://mywebservicehere/dostuff?url=https://www.website.com"));
request.Method = "GET";
using (var response = (HttpWebResponse) (await Task<WebResponse>.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null)))
{
var encoding = ASCIIEncoding.ASCII;
StreamReader reader = new StreamReader(response.GetResponseStream(), encoding);
}
想知道其他人可能使用过的替代方法吗?感谢您的帮助!
I wanted some insights into the relevance of the GetResponse method, it appears to deprecated now.
它没有被弃用,在 UWP 的 .NET 中,它是一种异步方法。
WebRequest req = WebRequest.Create("[URL here]");
WebResponse rep = await req.GetResponseAsync();
Wanted to know of any alternative methods others may have used?
除了 WebRequest class,Windows Runtime Platform 中还有另外 2 个 HttpClient classes,您可以使用它来获取 http 响应。
var client1 = new System.Net.Http.HttpClient();
var client2 = new Windows.Web.Http.HttpClient();
System.Net.Http.HttpClient 在 .NET for UWP 中。 Windows.Web.Http.HttpClient 在 Windows 运行时。