/// <summary> /// Creates a new request using client's own configurations. /// </summary> /// <param name="url">Request's url address.</param> /// <returns>Returns a new HttpWebRequest</returns> private HttpWebRequest CreateRequest(string url, NewContentHandler callback, byte[] data = null) { HttpWebRequest request = null; request = (HttpWebRequest)WebRequest.Create(url); request.CookieContainer = Cookies; if (Headers.ContainsKey("Accept")) { request.Accept = Headers["Accept"]; } if (Headers.ContainsKey("Connection")) { request.KeepAlive = Headers["Connection"].Equals("keep-alive"); } if (Headers.ContainsKey("UserAgent")) { request.UserAgent = Headers["UserAgent"]; } if (Headers.ContainsKey("Referer")) { request.Referer = Headers["Referer"]; } if (Headers.ContainsKey("Accept-Encoding")) { // request.Headers.Add(HttpRequestHeader.AcceptEncoding, Headers["Accept-Encoding"]); } foreach (var key in Headers.Keys) { if (!key.IsIn( "Accept", "Content-Type", "Referer", "Connection", "Host")) { request.Headers.Add(key, Headers[key]); } } if (data != null) { request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; request.GetRequestStream().Write(data, 0, data.Length); } request.Timeout = 15000; Requests.Add(request, callback); return(request); }
/// <summary> /// Creates a new request using client's own configurations. /// </summary> /// <param name="url">Request's url address.</param> /// <returns>Returns a new HttpWebRequest</returns> private HttpWebRequest CreateRequest(string url, NewContentHandler callback, byte[] data = null) { HttpWebRequest request = null; request = (HttpWebRequest) WebRequest.Create(url); request.CookieContainer = Cookies; if (Headers.ContainsKey("Accept")) { request.Accept = Headers["Accept"]; } if (Headers.ContainsKey("Connection")) { request.KeepAlive = Headers["Connection"].Equals("keep-alive"); } if (Headers.ContainsKey("UserAgent")) { request.UserAgent = Headers["UserAgent"]; } if (Headers.ContainsKey("Referer")) { request.Referer = Headers["Referer"]; } if (Headers.ContainsKey("Accept-Encoding")) { // request.Headers.Add(HttpRequestHeader.AcceptEncoding, Headers["Accept-Encoding"]); } foreach (var key in Headers.Keys) { if (!key.IsIn( "Accept", "Content-Type", "Referer", "Connection", "Host")) { request.Headers.Add(key, Headers[key]); } } if (data != null) { request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; request.GetRequestStream().Write(data, 0, data.Length); } request.Timeout = 15000; Requests.Add(request, callback); return request; }
/// <summary> /// Makes requests to server. /// </summary> /// <param name="url">Url to be requested.</param> /// <param name="callback">Return function to run when response comes.</param> /// <param name="data">Data to post.</param> public void RequestContent(string url, NewContentHandler callback, byte[] data = null) { var request = CreateRequest(url, callback, data); SendRequest(request); }