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

using Apewer;
using Apewer.Internals;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
namespace Apewer.Network
{
/// <summary></summary>
public class HttpRequest
{
// ========================================
internal TextSet _properties = new TextSet(true);
internal TextSet _headers = new TextSet(true);
internal Action<Int64> _progress = null;
internal Stream _stream = null;
internal byte[] _data = Constant.EmptyBytes;
internal long _contentlength = 0L;
internal bool _locked = false;
internal int _timeout = 0;
// ----------------------------------------
internal CookieContainer _cookies = null;
internal List<byte[]> _certificates = new List<byte[]>();
internal HttpMethod _method = HttpMethod.GET;
internal bool _redirect = true;
// ========================================
/// <summary></summary>
public TextSet Headers { get { return _headers; } }
/// <summary>获取或设置 POST 请求发送的数据。当 Stream 属性有效时此属性将被忽略。</summary>
public byte[] Data { get { return _data; } set { _data = value ?? Constant.EmptyBytes; } }
/// <summary>获取或设置 POST 请求发送的数据。此属性有效时将忽略 Data 属性。</summary>
public Stream Stream { get { return _stream; } set { _stream = value; } }
/// <summary>获取或设置写入 Content 时的回调,每 1 KB 回调一次,默认为空。</summary>
public Action<Int64> ProgressCallback { get { return _progress; } set { _progress = value; } }
/// <summary>获取或设置 POST 请求的编码,默认为空。</summary>
public string TransferEncoding { get { return _properties["TransferEncoding"]; } set { _properties["TransferEncoding"] = value; } }
/// <summary>获取或设置 POST 请求的内容类型,默认为空。</summary>
public string ContentType { get { return _properties["ContentType"]; } set { _properties["ContentType"] = value; } }
/// <summary>获取或设置超时,默认值取决于运行时。</summary>
public int Timeout { get { return _timeout; } set { _timeout = value < 0 ? 0 : value; } }
/// <summary>获取或设置 POST 请求的内容字节长度。</summary>
public long ContentLength { get { return _contentlength; } set { _contentlength = value; } }
/// <summary>获取或设置将要请求的地址。</summary>
public string Url { get { return _properties["Url"]; } set { _properties["Url"] = value; } }
// ----------------------------------------
/// <summary></summary>
public CookieContainer Cookies { get { return _cookies; } set { _cookies = value; } }
/// <summary>获取或设置将要请求的方法,默认为 GET。</summary>
public HttpMethod Method { get { return _method; } set { _method = value; } }
/// <summary>获取或设置将要使用的证书,无效证书将被忽略。</summary>
public List<byte[]> Certificates { get { return _certificates; } }
/// <summary>获取或设置重定向,默认值为允许。</summary>
public bool AllowAutoRedirect { get { return _redirect; } set { _redirect = value; } }
/// <summary>获取或设置用户代理。</summary>
public string UserAgent { get { return _properties["UserAgent"]; } set { _properties["UserAgent"] = value; } }
/// <summary>获取或设置来源。</summary>
public string Referer { get { return _properties["Referer"]; } set { _properties["Referer"] = value; } }
// ========================================
}
}