You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.7 KiB

  1. using Apewer;
  2. using Apewer.Internals;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Net;
  7. using System.Text;
  8. namespace Apewer.Network
  9. {
  10. /// <summary></summary>
  11. public class HttpRequest
  12. {
  13. // ========================================
  14. internal TextSet _properties = new TextSet(true);
  15. internal TextSet _headers = new TextSet(true);
  16. internal Action<Int64> _progress = null;
  17. internal Stream _stream = null;
  18. internal byte[] _data = Constant.EmptyBytes;
  19. internal long _contentlength = 0L;
  20. internal bool _locked = false;
  21. internal int _timeout = 0;
  22. // ----------------------------------------
  23. internal CookieContainer _cookies = null;
  24. internal List<byte[]> _certificates = new List<byte[]>();
  25. internal HttpMethod _method = HttpMethod.GET;
  26. internal bool _redirect = true;
  27. // ========================================
  28. /// <summary></summary>
  29. public TextSet Headers { get { return _headers; } }
  30. /// <summary>获取或设置 POST 请求发送的数据。当 Stream 属性有效时此属性将被忽略。</summary>
  31. public byte[] Data { get { return _data; } set { _data = value ?? Constant.EmptyBytes; } }
  32. /// <summary>获取或设置 POST 请求发送的数据。此属性有效时将忽略 Data 属性。</summary>
  33. public Stream Stream { get { return _stream; } set { _stream = value; } }
  34. /// <summary>获取或设置写入 Content 时的回调,每 1 KB 回调一次,默认为空。</summary>
  35. public Action<Int64> ProgressCallback { get { return _progress; } set { _progress = value; } }
  36. /// <summary>获取或设置 POST 请求的编码,默认为空。</summary>
  37. public string TransferEncoding { get { return _properties["TransferEncoding"]; } set { _properties["TransferEncoding"] = value; } }
  38. /// <summary>获取或设置 POST 请求的内容类型,默认为空。</summary>
  39. public string ContentType { get { return _properties["ContentType"]; } set { _properties["ContentType"] = value; } }
  40. /// <summary>获取或设置超时,默认值取决于运行时。</summary>
  41. public int Timeout { get { return _timeout; } set { _timeout = value < 0 ? 0 : value; } }
  42. /// <summary>获取或设置 POST 请求的内容字节长度。</summary>
  43. public long ContentLength { get { return _contentlength; } set { _contentlength = value; } }
  44. /// <summary>获取或设置将要请求的地址。</summary>
  45. public string Url { get { return _properties["Url"]; } set { _properties["Url"] = value; } }
  46. // ----------------------------------------
  47. /// <summary></summary>
  48. public CookieContainer Cookies { get { return _cookies; } set { _cookies = value; } }
  49. /// <summary>获取或设置将要请求的方法,默认为 GET。</summary>
  50. public HttpMethod Method { get { return _method; } set { _method = value; } }
  51. /// <summary>获取或设置将要使用的证书,无效证书将被忽略。</summary>
  52. public List<byte[]> Certificates { get { return _certificates; } }
  53. /// <summary>获取或设置重定向,默认值为允许。</summary>
  54. public bool AllowAutoRedirect { get { return _redirect; } set { _redirect = value; } }
  55. /// <summary>获取或设置用户代理。</summary>
  56. public string UserAgent { get { return _properties["UserAgent"]; } set { _properties["UserAgent"] = value; } }
  57. /// <summary>获取或设置来源。</summary>
  58. public string Referer { get { return _properties["Referer"]; } set { _properties["Referer"] = value; } }
  59. // ========================================
  60. }
  61. }