Punkbastard

HttpClient Post Request Method - C#

Oct 28th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. async static void PostRequest(string url)
  2. {
  3.     IEnumerable<KeyValuePair<string, string>> queries = new List<KeyValuePair<string, string>>()
  4.             {
  5.                 new KeyValuePair<string, string>("query1", "number1"),
  6.                 new KeyValuePair<string, string>("query2", "number2")
  7.             };
  8.     HttpContent q = new FormUrlEncodedContent(queries);
  9.     using (HttpClient client = new HttpClient())
  10.     {
  11.         using (HttpResponseMessage response = await client.PostAsync(url, q))
  12.         {
  13.             using (HttpContent content = response.Content)
  14.             {
  15.                 string mycontent = await content.ReadAsStringAsync();
  16.                 HttpContentHeaders header = content.Headers;
  17.                 Console.WriteLine(mycontent);
  18.             }
  19.         }
  20.  
  21.     }
  22. }
Add Comment
Please, Sign In to add comment