且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使HTTP调用,使用ASP.NET MVC?

更新时间:2022-11-23 11:31:03

使用的 System.Net.Http.HttpClient

您可以使用类似以下从网站做一些基本的阅读:

You can do some basic reading from a website using something like the following:

using (var client = new HttpClient())
{
    var uri = new Uri("http://www.google.com/");

    var response = await client.GetAsync(uri);

    string textResult = await response.Content.ReadAsStringAsync();
}

您可能希望确保测试 response.IsSuccessStatus code (检查一个HTTP 200结果),以确保其结果是你在你面前的期望解析它。

You may want to make sure to test response.IsSuccessStatusCode (checks for an HTTP 200 result) to make sure the result is what you expect before you parse it.