Advertisement
kilya

Methode PostRequest

Dec 20th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1.         // Methode post request
  2.         async void PostRequest()
  3.         {
  4.             IEnumerable<KeyValuePair<string, string>> queries = new List<KeyValuePair<string, string>>()
  5.             {
  6.                 new KeyValuePair<string,string>("query1","Abdessalam"),
  7.                 new KeyValuePair<string,string>("query2","Kilya")
  8.             };
  9.             HttpContent q = new FormUrlEncodedContent(queries);
  10.             using (HttpClient client = new HttpClient())
  11.             {
  12.                 using (HttpResponseMessage response = await client.PostAsync("https://posttestserver.com/post.php", q))
  13.                 {
  14.                     using (HttpContent content = response.Content)
  15.                     {
  16.                         string mycontent = await content.ReadAsStringAsync();
  17.                         Console.WriteLine(mycontent);
  18.                     }
  19.                 }
  20.             }
  21.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement