static WebRequest() { #if MOBILE || SSHARP IWebRequestCreate http = new HttpRequestCreator(); RegisterPrefix("http", http); RegisterPrefix("https", http); RegisterPrefix("file", new FileWebRequestCreator()); RegisterPrefix("ftp", new FtpRequestCreator()); #else #if CONFIGURATION_DEP object cfg = ConfigurationManager.GetSection("system.net/webRequestModules"); WebRequestModulesSection s = cfg as WebRequestModulesSection; if (s != null) { foreach (WebRequestModuleElement el in s.WebRequestModules) { AddPrefix(el.Prefix, el.Type); } return; } #endif ConfigurationSettings.GetConfig("system.net/webRequestModules"); #endif }
public async Task The_Function_Should_Throw_A_Bad_Request_When_We_Dont_Pass_In_A_Request_Body() { var req = HttpRequestCreator.CreateRequest(); var logger = NullLogger.Instance; var response = await SharePost.Run(req, logger); Assert.IsTrue(response is BadRequestObjectResult); }
public async Task The_Function_Should_Return_An_Ok_Object_Result_When_We_Pass_In_A_Valid_Request_Body() { var req = await HttpRequestCreator.CreateRequest("www.google.com", "This is test content."); var logger = NullLogger.Instance; var response = await SharePost.Run(req, logger); Assert.IsTrue(response is OkObjectResult); }
public async Task The_Function_Should_Throw_A_Bad_Request_When_We_Dont_Pass_In_Data_For_Properties( string postUrl, string postContent) { var req = await HttpRequestCreator.CreateRequest(postUrl, postContent); var logger = NullLogger.Instance; var response = await SharePost.Run(req, logger); Assert.IsTrue(response is BadRequestObjectResult); }
private void _Request(string _url , byte[] _bytes) { // HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create( _url); HttpRequestCreator httpRequestCreator = new HttpRequestCreator(); Uri _uri = new Uri( _url); HttpWebRequest httpRequest = (HttpWebRequest)httpRequestCreator.Create( _uri); httpRequest.ContentLength = _bytes.Length; httpRequest.Method = "POST"; httpRequest.ContentType = "application/json; charset=UTF-8"; httpRequest.KeepAlive = false; Stream requestStream = httpRequest.GetRequestStream(); requestStream.Write( _bytes, 0, _bytes.Length); requestStream.Close(); HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse(); Stream responseStream = httpResponse.GetResponseStream(); StreamReader streamReader = new StreamReader( responseStream, Encoding.Default); string pageContent = streamReader.ReadToEnd(); Debug.Log( "AsWebRequest::_Request(), url: " + _url); Debug.Log( "AsWebRequest::_Request(), response: " + pageContent); streamReader.Close(); responseStream.Close(); httpResponse.Close(); }
// Token: 0x06000031 RID: 49 RVA: 0x00002C58 File Offset: 0x00000E58 public HttpResponse Row(Uri url, HttpMethod method, HttpContent content = null) { HttpResponse httpResponse = new HttpResponse(); try { HttpRequestCreator httpRequestCreator = new HttpRequestCreator(); bool ssl = this.Ssl; if (ssl) { httpRequestCreator.Settings.SslAcceptAllCertificates = false; } else { httpRequestCreator.Settings.SslAcceptAllCertificates = true; } httpRequestCreator.ValidatingCertificate += this.Creator_ValidatingCertificate; httpRequestCreator.Settings.SslAllowedVersions = TlsVersion.Any; bool flag = this.UseProxy && this.Proxy != null; if (flag) { Proxy proxy = this.Proxy; proxy.SendRetryTimeout = this.TimeOut; httpRequestCreator.Proxy = proxy; } var httpRequest = new Rebex.Net.HttpRequest(url, httpRequestCreator); httpRequest.Method = this.Method(method); httpRequest.ContinueTimeout = this.TimeOut; httpRequest.Timeout = this.TimeOut; bool flag2 = this.Headers.Count > 0; if (flag2) { foreach (KeyValuePair <string, string> keyValuePair in this.Headers) { httpRequest.Headers.Add(keyValuePair.Key, keyValuePair.Value); } } bool flag3 = this.UserAgent != string.Empty; if (flag3) { httpRequest.UserAgent = this.UserAgent; } bool flag4 = this.Referer != string.Empty; if (flag4) { httpRequest.Referer = this.Referer; } bool expect = this.Expect100; if (expect) { httpRequest.Expect100Continue = true; } else { httpRequest.Expect100Continue = false; } bool flag5 = this.Cookies.Count > 0; if (flag5) { httpRequest.Headers.Add(HttpRequestHeader.Cookie, this.Cookies.ToString()); } httpRequest.Method = this.Method(method); httpRequest.KeepAlive = this.KeepAlive; httpRequest.AllowAutoRedirect = this.AllowAutoRedirect; bool flag6 = content != null; if (flag6) { byte[] data = content.GetData(); httpRequest.ContentType = content.ContentType; httpRequest.ContentLength = content.GetContentLength(); using (Stream requestStream = httpRequest.GetRequestStream()) { requestStream.Write(data, 0, data.Length); } } using (var httpResponse2 = (Rebex.Net.HttpResponse)httpRequest.GetResponse()) { httpResponse.ContentEncoding = httpResponse2.ContentEncoding; httpResponse.ContentLength = httpResponse2.ContentLength; httpResponse.ContentType = httpResponse2.ContentType; httpResponse.TlsCipher = httpResponse2.Cipher; httpResponse.CharacterSet = httpResponse2.CharacterSet; httpResponse.Address = httpResponse2.ResponseUri; httpResponse.StatusCode = httpResponse2.StatusCode; httpResponse.Headers = new HeaderDictionary(httpResponse2.Headers); httpResponse.Cookies = this.Cookies.SetCookie(httpResponse2.Headers); using (StreamReader streamReader = new StreamReader(httpResponse2.GetResponseStream())) { httpResponse.Content = streamReader.ReadToEnd(); } } } catch (WebException ex) { var httpResponse3 = (Rebex.Net.HttpResponse)ex.Response; bool flag7 = httpResponse3 != null; if (!flag7) { throw new HttpException(ex.Message); } httpResponse.ContentEncoding = httpResponse3.ContentEncoding; httpResponse.ContentLength = httpResponse3.ContentLength; httpResponse.ContentType = httpResponse3.ContentType; httpResponse.TlsCipher = httpResponse3.Cipher; httpResponse.CharacterSet = httpResponse3.CharacterSet; httpResponse.Address = httpResponse3.ResponseUri; httpResponse.StatusCode = httpResponse3.StatusCode; httpResponse.Headers = new HeaderDictionary(httpResponse3.Headers); httpResponse.Cookies = this.Cookies.SetCookie(httpResponse3.Headers); using (StreamReader streamReader2 = new StreamReader(httpResponse3.GetResponseStream())) { httpResponse.Content = streamReader2.ReadToEnd(); } } return(httpResponse); }
// Token: 0x06000032 RID: 50 RVA: 0x00003104 File Offset: 0x00001304 public async Task <HttpResponse> RowAsync(Uri url, HttpMethod method, HttpContent content = null) { HttpResponse res = new HttpResponse(); try { HttpRequestCreator creator = new HttpRequestCreator(); bool ssl = this.Ssl; if (ssl) { creator.Settings.SslAcceptAllCertificates = false; } else { creator.Settings.SslAcceptAllCertificates = true; } creator.ValidatingCertificate += this.Creator_ValidatingCertificate; creator.Settings.SslAllowedVersions = TlsVersion.Any; bool flag = this.UseProxy && this.Proxy != null; if (flag) { Proxy proxy = this.Proxy; proxy.SendRetryTimeout = this.TimeOut; creator.Proxy = proxy; proxy = null; } var request = new Rebex.Net.HttpRequest(url, creator); request.Method = this.Method(method); request.ContinueTimeout = this.TimeOut; request.Timeout = this.TimeOut; bool flag2 = this.Headers.Count > 0; if (flag2) { foreach (KeyValuePair <string, string> item in this.Headers) { request.Headers.Add(item.Key, item.Value); } } bool flag3 = this.UserAgent != string.Empty; if (flag3) { request.UserAgent = this.UserAgent; } bool flag4 = this.Referer != string.Empty; if (flag4) { request.Referer = this.Referer; } bool expect = this.Expect100; if (expect) { request.Expect100Continue = true; } else { request.Expect100Continue = false; } bool flag5 = this.Cookies.Count > 0; if (flag5) { request.Headers.Add(HttpRequestHeader.Cookie, this.Cookies.ToString()); } request.Method = this.Method(method); request.KeepAlive = this.KeepAlive; request.AllowAutoRedirect = this.AllowAutoRedirect; bool flag6 = content != null; if (flag6) { byte[] postData = content.GetData(); request.ContentType = content.ContentType; request.ContentLength = content.GetContentLength(); Stream stream2 = await request.GetRequestStreamAsync(); Stream stream = stream2; stream2 = null; try { stream.Write(postData, 0, postData.Length); } finally { if (stream != null) { ((IDisposable)stream).Dispose(); } } stream = null; postData = null; } WebResponse webResponse = await request.GetResponseAsync(); var response = (Rebex.Net.HttpResponse)webResponse; webResponse = null; try { res.ContentEncoding = response.ContentEncoding; res.ContentLength = response.ContentLength; res.ContentType = response.ContentType; res.TlsCipher = response.Cipher; res.CharacterSet = response.CharacterSet; res.Address = response.ResponseUri; res.StatusCode = response.StatusCode; res.Headers = new HeaderDictionary(response.Headers); res.Cookies = this.Cookies.SetCookie(response.Headers); using (StreamReader sr = new StreamReader(response.GetResponseStream())) { HttpResponse httpResponse = res; string content2 = await sr.ReadToEndAsync(); httpResponse.Content = content2; httpResponse = null; content2 = null; } //StreamReader sr = null; } finally { if (response != null) { ((IDisposable)response).Dispose(); } } response = null; creator = null; request = null; } catch (WebException obj) { WebException ex = obj; var response2 = (Rebex.Net.HttpResponse)ex.Response; if (response2 == null) { throw new HttpException(ex.Message); } res.ContentEncoding = response2.ContentEncoding; res.ContentLength = response2.ContentLength; res.ContentType = response2.ContentType; res.TlsCipher = response2.Cipher; res.CharacterSet = response2.CharacterSet; res.Address = response2.ResponseUri; res.StatusCode = response2.StatusCode; res.Headers = new HeaderDictionary(response2.Headers); res.Cookies = this.Cookies.SetCookie(response2.Headers); using (StreamReader sr2 = new StreamReader(response2.GetResponseStream())) { HttpResponse httpResponse2 = res; string content3 = await sr2.ReadToEndAsync(); httpResponse2.Content = content3; httpResponse2 = null; content3 = null; } //StreamReader sr2 = null; response2 = null; ex = null; } return(res); }