using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace RequestBinExample
{
class Program
{
static void Main(string[] args)
{
var task = MakeRequest();
task.Wait();
var response = task.Result;
var body = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(body);
}
private static async Task<HttpResponseMessage> MakeRequest()
{
var httpClient = new HttpClient();
return await httpClient.GetAsync(new Uri("http://requestb.in/1hui2vv1"));
}
}
}
答案 0 :(得分:0)
class Program
{
static void Main(string[] args)
{
var task = MakeRequest();
task.Wait();
var response = task.Result;
var body = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(body);
Console.Read();
}
private static async Task<HttpResponseMessage> MakeRequest()
{
var httpClient = new HttpClient();
HttpContent requestContent = new StringContent("I am the message body");
return await httpClient.PostAsync("https://requestb.in/188bhf01", requestContent);
}
}
我认为这应该可以解决问题。