/// <summary> /// 重新构造相同的 HTTP 请求,用于重复当前请求。 /// </summary> public HttpRequest RebuildRequest() { if (State == HttpRequestState.Connecting || State == HttpRequestState.Progressing) { throw new InvalidOperationException("不能对传输中的请求进行修改。"); } var oldRequest = Request; Request = WebRequest.CreateHttp(oldRequest.RequestUri); Request?.Abort(); ResultStream?.Dispose(); Request.Accept = oldRequest.Accept; Request.AllowReadStreamBuffering = oldRequest.AllowReadStreamBuffering; Request.ContentType = oldRequest.ContentType; Request.ContinueTimeout = oldRequest.ContinueTimeout; Request.CookieContainer = oldRequest.CookieContainer; Request.Credentials = oldRequest.Credentials; Request.Headers = oldRequest.Headers; Request.Method = oldRequest.Method; Request.Proxy = oldRequest.Proxy; Request.UseDefaultCredentials = oldRequest.UseDefaultCredentials; State = HttpRequestState.NothingSpecial; return(this); }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { lock (_lock) { _isDisposed = true; _waitHandle.Close(); ResultStream?.Dispose(); } }
public void Dispose() { Response?.Dispose(); ResultStream?.Dispose(); }