private string RequestInternal(Uri uri, string method, byte[] data, string contentType) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri); req.CookieContainer = Cookies; req.UserAgent = UserAgent; req.AllowAutoRedirect = AllowAutoRedirect; req.Referer = Referer; req.Method = method; req.ContentType = contentType; SetRequest?.Invoke(this, new EventArgs <HttpWebRequest>(req)); if ((data != null) && data.Any() && (method != WebRequestMethods.Http.Get) && (method != WebRequestMethods.Http.Head)) { req.ContentLength = data.Length; using (Stream stream = req.GetRequestStream()) { stream.Write(data, 0, data.Length); } } HttpWebResponse res = (HttpWebResponse)req.GetResponse(); GotResponse?.Invoke(this, new EventArgs <HttpWebResponse>(res)); using (StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding)) { return(sr.ReadToEnd()); } }
protected override WebRequest GetWebRequest(Uri address) { HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address); SetRequest?.Invoke(this, new EventArgs <HttpWebRequest>(request)); return(request); }
private async Task <(bool, string)> RequestInternalAsync(Uri uri, HttpMethod httpMethod, byte[] data, string contentType) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri); req.CookieContainer = Cookies; req.UserAgent = UserAgent; req.AllowAutoRedirect = AllowAutoRedirect; req.Referer = Referer; req.Method = httpMethod.Method; req.ContentType = contentType; SetRequest?.Invoke(this, new EventArgs <HttpWebRequest>(req)); if (data != null && data.Any() && (httpMethod != HttpMethod.Get) && (httpMethod != HttpMethod.Head)) { req.ContentLength = data.Length; using (Stream stream = await req.GetRequestStreamAsync().ConfigureAwait(false)) { await stream.WriteAsync(data, 0, data.Length).ConfigureAwait(false); } } HttpWebResponse res = (HttpWebResponse)(await req.GetResponseAsync().ConfigureAwait(false)); GotResponse?.Invoke(this, new EventArgs <HttpWebResponse>(res)); Stream responseStream = res.GetResponseStream(); using (StreamReader sr = new StreamReader(responseStream, Encoding)) { string response = await sr.ReadToEndAsync().ConfigureAwait(false); return(IsSuccessStatusCode((int)res.StatusCode), response); } }
protected override WebRequest GetWebRequest(Uri address) { HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address); SetRequest?.Invoke(this, new EventArgs <HttpWebRequest>(request)); long length = _uriContexts[address].CurrentFileLength; if (length > 0) { request.AddRange(length); } _uriContexts[address].Request = request; return(request); }
protected virtual void OnSetRequest(int newTemp, string token) { SetRequest?.Invoke(this, new SetRequestEventArgs(newTemp, token)); }