HttpToolPlus.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using Azylee.Jsons;
  2. using Azylee.YeahWeb.HttpUtils.MethodUtils.GetUtils;
  3. using Azylee.YeahWeb.HttpUtils.MethodUtils.PostUtils;
  4. using Azylee.YeahWeb.HttpUtils.Models;
  5. using System.Collections.Generic;
  6. using System.Net;
  7. using System.Text;
  8. namespace Azylee.YeahWeb.HttpUtils
  9. {
  10. public class HttpToolPlus
  11. {
  12. public static string Get(string url, ref CookieCollection cookie, Dictionary<string, string> headers = null, string contentType = HttpContentTypes.ApplicationXWwwFormUrlEncoded, bool autoRedirect = false, bool keepAlive = true, string userAgent = UserAgents.Mozilla4)
  13. {
  14. return GetToolPlus.Get(url, ref cookie, headers = null, contentType, autoRedirect, keepAlive, userAgent);
  15. }
  16. public static string Post(string url, ref CookieCollection cookie, Dictionary<string, string> data = null, Encoding encoding = null, Dictionary<string, string> headers = null, string contentType = HttpContentTypes.ApplicationXWwwFormUrlEncoded, bool autoRedirect = true, bool keepAlive = true, string userAgent = UserAgents.Mozilla4)
  17. {
  18. string param = null;
  19. try
  20. {
  21. if (data != null && data.Count > 0)
  22. {
  23. StringBuilder sb = new StringBuilder();
  24. foreach (var item in data)
  25. {
  26. sb.Append($"&{item.Key}={item.Value}");
  27. }
  28. param = sb.ToString().Substring(1);
  29. }
  30. }
  31. catch { }
  32. return PostToolPlus.Post(url, ref cookie, param, encoding, headers, contentType, autoRedirect, keepAlive, userAgent);
  33. }
  34. public static string PostJson(string url, ref CookieCollection cookie, object data, Encoding encoding = null, Dictionary<string, string> headers = null, bool autoRedirect = true, bool keepAlive = true, string userAgent = UserAgents.Mozilla4)
  35. {
  36. string param = Json.Object2String(data);
  37. return PostToolPlus.Post(url, ref cookie, param, encoding, headers, HttpContentTypes.ApplicationJson, autoRedirect, keepAlive, userAgent);
  38. }
  39. }
  40. }