コード例 #1
0
ファイル: TestRequester.cs プロジェクト: rrsc/AngleSharp
        public void MethodNotAllowedOnHttpPut()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultHttpRequester();
                var request = new DefaultHttpRequest();
                request.Address = new Uri("http://httpbin.org/get");
                request.Method = HttpMethod.PUT;
                request.Content = Helper.StreamFromString("Should be ignored");

                var response = http.Request(request);
                Assert.IsNotNull(response);
                Assert.AreEqual(405, (int)response.StatusCode);
                Assert.IsTrue(response.Content.CanRead);
                Assert.IsTrue(response.Headers.Count > 0);
            }
        }
コード例 #2
0
ファイル: TestRequester.cs プロジェクト: rrsc/AngleSharp
        public void RequestUserAgentString()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultHttpRequester();
                var request = new DefaultHttpRequest();
                request.Address = new Uri("http://httpbin.org/user-agent");
                request.Method = HttpMethod.GET;

                var response = http.Request(request);
                Assert.IsNotNull(response);
                Assert.AreEqual(200, (int)response.StatusCode);
                Assert.IsTrue(response.Content.CanRead);
                Assert.IsTrue(response.Headers.Count > 0);

                var stream = new StreamReader(response.Content);
                Assert.IsNotNull(stream);

                var content = stream.ReadToEnd();
                Assert.IsTrue(content.Length > 0);
                Assert.AreEqual("{\n  \"user-agent\": \"" + Info.Agent + "\"\n}", content);
            }
        }
コード例 #3
0
ファイル: TestRequester.cs プロジェクト: rrsc/AngleSharp
        public void StatusCode500OfHttpGetRequest()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultHttpRequester();
                var request = new DefaultHttpRequest();
                request.Address = new Uri("http://httpbin.org/status/500");
                request.Method = HttpMethod.GET;

                var response = http.Request(request);
                Assert.IsNotNull(response);
                Assert.AreEqual(500, (int)response.StatusCode);
                Assert.IsTrue(response.Content.CanRead);
                Assert.IsTrue(response.Headers.Count > 0);
            }
        }
コード例 #4
0
ファイル: TestRequester.cs プロジェクト: rrsc/AngleSharp
        public void SimpleHttpPutRequest()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultHttpRequester();
                var request = new DefaultHttpRequest();
                request.Address = new Uri("http://httpbin.org/put");
                request.Method = HttpMethod.PUT;
                request.Content = Helper.StreamFromString("PUT THIS THING BACK");

                var response = http.Request(request);
                Assert.IsNotNull(response);
                Assert.AreEqual(200, (int)response.StatusCode);
                Assert.IsTrue(response.Content.CanRead);
                Assert.IsTrue(response.Headers.Count > 0);

                var stream = new StreamReader(response.Content);
                Assert.IsNotNull(stream);

                var content = stream.ReadToEnd();
                Assert.IsTrue(content.Length > 0);
                Assert.IsTrue(content.Contains("\"data\": \"PUT THIS THING BACK\""));
            }
        }
コード例 #5
0
ファイル: TestRequester.cs プロジェクト: rrsc/AngleSharp
        public void SimpleHttpGetRequest()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultHttpRequester();
                var request = new DefaultHttpRequest();
                request.Address = new Uri("http://httpbin.org/robots.txt");
                request.Method = HttpMethod.GET;

                var response = http.Request(request);
                Assert.IsNotNull(response);
                Assert.AreEqual(200, (int)response.StatusCode);
                Assert.IsTrue(response.Content.CanRead);
                Assert.IsTrue(response.Headers.Count > 0);

                var content = new StreamReader(response.Content);
                Assert.AreEqual("User-agent: *\nDisallow: /deny\n", content.ReadToEnd());
            }
        }
コード例 #6
0
ファイル: TestRequester.cs プロジェクト: rrsc/AngleSharp
        public void SimpleHttpDeleteRequest()
        {
            if (Helper.IsNetworkAvailable())
            {
                var http = new DefaultHttpRequester();
                var request = new DefaultHttpRequest();
                request.Address = new Uri("http://httpbin.org/delete");
                request.Method = HttpMethod.DELETE;
                request.Content = Helper.StreamFromString("Should be ignored");

                var response = http.Request(request);
                Assert.IsNotNull(response);
                Assert.AreEqual(200, (int)response.StatusCode);
                Assert.IsTrue(response.Content.CanRead);
                Assert.IsTrue(response.Headers.Count > 0);
            }
        }