Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. private static HttpResponseMessage PostRequest(string json, string url)
  2. {
  3. Task<HttpResponseMessage> task = Task.Run(async () => await PostRequestAsync(json, url));
  4. task.Wait();
  5. return task.Result;
  6. }
  7.  
  8. private static async Task<HttpResponseMessage> PostRequestAsync(string json, string url)
  9. {
  10. try
  11. {
  12. HttpResponseMessage response = await client.PostAsync(url, new StringContent(json, Encoding.UTF8, "application/json"));
  13. return response;
  14. }
  15. catch (HttpRequestException exc)
  16. {
  17. ThreadKill();
  18. Console.WriteLine(exc.InnerException.Message);
  19. Console.WriteLine("Press enter to exit...");
  20. Console.ReadLine();
  21. Environment.Exit(1);
  22. return new HttpResponseMessage();
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement