在.NET中调用HTTP接口通常有几种方法,以下是一些常用的方式:
1. 使用 `HttpClient`
`HttpClient` 是.NET框架中用于发送HTTP请求的类,它提供了异步和非异步的方法。
异步方式
```csharp
using System.Net.Http;
using System.Threading.Tasks;
public async Task
{
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();