public async void TestGET()
 {
     var request = new HttpRequest(new Uri("http://www.bing.com"));
     var response = await request.GetResponseAsync().ConfigureAwait(false);
     Assert.AreEqual("http://cn.bing.com/", response.ResponseUri.AbsoluteUri);
     response.Close();
 }       
Beispiel #2
0
        public async void TestProxyWithRedirect()
        {
            var proxy = new System.Net.WebProxy("127.0.0.1", 8580);
            proxy.BypassList = new string[] { "http://www.bing.com" };

            //use a proxy 
            var request = new HttpRequest(new Uri("http://www.google.com"))
            {               
                Proxy = proxy
            };
            var response = await request.GetResponseAsync().ConfigureAwait(false);
            Assert.AreEqual(200, (int)response.StatusCode);
            Assert.AreEqual("www.google.com", response.ResponseUri.Host);
            response.Close();

            //disable a proxy
           request = new HttpRequest(new Uri("http://www.bing.com"))
            {
                Proxy = proxy                
            };          
           response = await request.GetResponseAsync().ConfigureAwait(false);
            Assert.AreEqual(200, (int)response.StatusCode);
            Assert.AreEqual("cn.bing.com", response.ResponseUri.Host);
            response.Close();
        }
Beispiel #3
0
 public async void TestHttp2Https()
 {            
     var request = new HttpRequest(new Uri("http://www.github.com"));            
     var response = await request.GetResponseAsync().ConfigureAwait(false);
     Assert.AreEqual(200, (int)response.StatusCode);
     Assert.AreEqual("https", response.ResponseUri.Scheme);
     Assert.AreEqual("https://github.com/", response.ResponseUri.AbsoluteUri);
 }
Beispiel #4
0
 public async void TestProxy()
 {
     var proxy = new System.Net.WebProxy("127.0.0.1", 8580);
     var request = new HttpRequest(new Uri("http://www.google.com"))
     {
         Proxy = proxy
     };
     var response = await request.GetResponseAsync().ConfigureAwait(false);
     Assert.AreEqual(200, (int)response.StatusCode);
 }
 public async void TestOptions()
 {
     var request = new HttpRequest(new Uri("http://www.bing.com"))
     {
         Method = HttpMethod.Options
     };
     var response = await request.GetResponseAsync().ConfigureAwait(false);
     Assert.AreEqual(405, (int)response.StatusCode);//405 Method Not Allowed
     Assert.AreEqual("GET,HEAD,TRACE", response.Headers["Allow"]);
     response.Close();
 }
 public async void TestHEAD()
 {
     var request = new HttpRequest(new Uri("http://cn.bing.com"))
     {
         Method = HttpMethod.Head
     };
     var response = await request.GetResponseAsync().ConfigureAwait(false);
     Assert.AreEqual("http://cn.bing.com/", response.ResponseUri.AbsoluteUri);
     Assert.IsNull(response.GetResponseStream());
     response.Close();
 }
Beispiel #7
0
 public async void TesDisableRedirect()
 {
     var request = new HttpRequest(new Uri("http://www.bing.com"))
     {
         AllowAutoRedirect = false
     };
     var response = await request.GetResponseAsync().ConfigureAwait(false);
     Assert.AreEqual("http://www.bing.com/", response.ResponseUri.AbsoluteUri);
     Assert.AreEqual(301, (int)response.StatusCode);
     response.Close();
 }
Beispiel #8
0
 internal ConnectStream(Connection connection, ArraySegment<byte> buffer, int offset, int bufferCount, long readCount, bool chunked, HttpRequest request)
 {
     _connection = connection;
     _readBytes = readCount;
     _chunked = chunked;
     if (_chunked)
     {
         _chunkParser = new ChunkParser(connection, buffer, offset, bufferCount);
     }
     else
     {
         _readBuffer = buffer;
         _readOffset = offset;
         _readBufferSize = bufferCount;
     }
     _request = request;
     _pooledBuffer = connection.Buffer;
 }
 public async void TestPOST()
 {
     var request = new HttpRequest(new Uri("http://api.jquery.com/"))
     {
         Method = HttpMethod.Post
     };
     var post_stream = request.GetRequestStream();
     request.Headers.ContentType = "application/x-www-form-urlencoded";            
     var bytes = Encoding.UTF8.GetBytes("s=ajax");//search ajax keywords
     post_stream.Write(bytes, 0, bytes.Length);
     post_stream.Close();
     var response = await request.GetResponseAsync().ConfigureAwait(false);
     Assert.AreEqual(200,(int) response.StatusCode);
     using (var sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
     {               
         var index = sr.ReadToEnd().IndexOf("<span>ajax</span>");
         Assert.IsTrue(index > 0);
     }
     response.Close();
 }
Beispiel #10
0
 internal ConnectStream(Connection connection, HttpRequest request)
 {
     _connection = connection;
     _request = request;
 }
Beispiel #11
0
 public async void TestAutoDecompression()
 {
     var request = new HttpRequest(new Uri("http://www.bing.com"))
     {
         AutomaticDecompression = true
     };
     request.Headers.AcceptEncoding = "gzip,deflate";            
     var response = await request.GetResponseAsync().ConfigureAwait(false);
     Assert.IsNotNull(response.Headers.ContentEncoding);
     using (var sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
     {
         var html = sr.ReadToEnd();
         Console.WriteLine(html);
         sr.Close();
     }
     response.Close();
 }
Beispiel #12
0
 public async void TestSmallBuffer()
 {
     var request = new HttpRequest(new Uri("http://cn.bing.com"));
     request.BuffSize = 15;
     var response = await request.GetResponseAsync().ConfigureAwait(false);
     Assert.AreEqual(200, (int)response.StatusCode);
 }
Beispiel #13
0
 public async void TestHttps()
 {
     var request = new HttpRequest(new Uri("https://www.bing.com"));
     var response = await request.GetResponseAsync().ConfigureAwait(false);
     Assert.AreEqual(200, (int)response.StatusCode);
 }
Beispiel #14
0
 public async void TestPost()
 {
     var request = new HttpRequest(new Uri("http://api.jquery.com/"));
     var bytes = Encoding.UTF8.GetBytes("s=ajax");//search ajax keywords
     var response = await request.PostAsync(bytes).ConfigureAwait(false);
     Assert.AreEqual(200, (int)response.StatusCode);
 }
Beispiel #15
0
 public async void TestGetString()
 {
     var request = new HttpRequest(new Uri("http://cn.bing.com"));
     var html = await request.GetStringAsync().ConfigureAwait(false);
     Assert.IsNotNull(html);
 }