如何更改C#.NET RequestBin HTTP API的文本正文?

时间:2017-03-29 13:52:47

标签: c# .net api http

嘿伙计们我是C#的新手,我想在另一个youtube视频中看到它后尝试使用Request Bin,但是这是一个PHP视频,你们中的任何人都可以告诉我如何实现一个文本体请求所以我可以在网站上看到它?谢谢你:D这是我现在的代码。

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"));
    }
  }
}

1 个答案:

答案 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);
    }
}

我认为这应该可以解决问题。