HttpClientHelper.cs 670 B

123456789101112131415161718192021222324
  1. using System;
  2. using System.IO;
  3. using System.Net.Http;
  4. namespace ET.Client
  5. {
  6. public static class HttpClientHelper
  7. {
  8. public static async ETTask<string> Get(string link)
  9. {
  10. try
  11. {
  12. using HttpClient httpClient = new HttpClient();
  13. HttpResponseMessage response = await httpClient.GetAsync(link);
  14. string result = await response.Content.ReadAsStringAsync();
  15. return result;
  16. }
  17. catch (Exception e)
  18. {
  19. throw new Exception($"http request fail: {link.Substring(0,link.IndexOf('?'))}\n{e}");
  20. }
  21. }
  22. }
  23. }