/// <summary> /// 发送请求方法 /// </summary> protected void MakeRequest() { if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException("url is empty"); } try { HttpWebRequest request = this.GetWebRequest(url); request.CookieContainer = Cookies.Container; request.Method = method.ToString().ToUpper(); request.AllowAutoRedirect = false; if (method == HttpVerb.Get || method == HttpVerb.Head) { ExecuteRequestWithoutBody(request); } else { request.ContentType = body.GetContentType(); ExecuteRequestWithBody(request); } } catch (WebException webEx) { action.Fail(webEx); } }
protected void MakeRequest() { // 授权请求 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException("url is empty"); } try { /* * Create new Request */ HttpWebRequest request = this.GetWebRequest(url); request.CookieContainer = Cookies.Container; request.Method = method.ToString().ToUpper(); if (headers != null) { request.Headers = GetHeadersFromProvider(headers.GetHeaders()); } if (body != null) { byte[] data = body.getBodyParameter(); request.ContentType = body.GetContentType(); using (Stream stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } } if (sync) { ExecuteSyncRequest(request); } else { ExecuteRequest(request); } } catch (WebException webEx) { action.Fail(webEx); } }
protected void MakeRequest() { if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException("url is empty"); } try { /* * Create new Request */ HttpWebRequest request = this.GetWebRequest(url); request.CookieContainer = Cookie.cookies; request.Method = method.ToString().ToUpper(); //Referer if (!string.IsNullOrEmpty(this.referer)) { request.Referer = this.referer; } //Timeout if (this.timeout != null) { request.Timeout = this.timeout.Value; } if (method == HttpVerb.Get || method == HttpVerb.Head) { ExecuteRequestWithoutBody(request); } else { request.ContentType = body.GetContentType(); ExecuteRequestWithBody(request); } } catch (WebException webEx) { action.Fail(webEx); } }
protected void MakeRequest() { if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentNullException("url is empty"); } try { /* * Create new Request */ HttpWebRequest request = this.GetWebRequest(url); request.CookieContainer = Cookies.Container; request.Method = method.ToString().ToUpper(); if (action != null && action.Make != null) { action.Make(request); //Pass the request out } if (headers != null) { request.Headers = GetHeadersFromProvider(request.RequestUri, headers.GetHeaders()); } if (method == HttpVerb.Get || method == HttpVerb.Head || body == null) { ExecuteRequestWithoutBody(request); } else { request.ContentType = body.GetContentType(); ExecuteRequestWithBody(request); } } catch (WebException webEx) { action.Fail(webEx); } }
private RequestData MakeRealTimeRequest() { Stream stream = null; try { HttpWebRequest request = CreateNewRequest(); if (method == HttpVerb.Get || method == HttpVerb.Head) { stream = (request.GetResponse()).GetResponseStream(); } else { if (request.ContentType == null) { request.ContentType = body.GetContentType(); } using (Stream myRequestStream = request.GetRequestStream()) { var contentLength = body.GetBody().Length; byte[] bodyBytes = new byte[contentLength]; body.GetBody().Read(bodyBytes, 0, bodyBytes.Length); body.GetBody().Seek(0, SeekOrigin.Begin); int maxLength = 500; int ec; for (int i = 0; i < contentLength; i += maxLength) { if (i + maxLength < contentLength) { ec = 500; } else { ec = (int)contentLength - i; } myRequestStream.Write(bodyBytes, i, ec); } HttpWebResponse response = (HttpWebResponse)request.GetResponse(); stream = response.GetResponseStream(); //using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) //{ // stream = response.GetResponseStream(); //} } } } catch (WebException webEx) { if (action.Fail != null) { action.Fail(webEx); } else { throw webEx; } } return(new RequestData(stream)); }