public static void DoGetWithRedirects2()
        {
            HttpClient httpClient = new HttpClient();
            HttpGet httpGet = new HttpGet(new Uri("http://www.codescales.com/home"));

            HttpBehavior httpBehavior = new HttpBehavior();
            httpBehavior.AddStep(301, "http://www.codescales.com");
            httpBehavior.AddStep(200);

            HttpResponse httpResponse = httpClient.Execute(httpGet, httpBehavior);

            Console.WriteLine("Response Code: " + httpResponse.ResponseCode);
            Console.WriteLine("Response Code: " + httpResponse.Location);
            Console.WriteLine("Response Content: " + EntityUtils.ToString(httpResponse.Entity));
        }
        public void HttpGetWithRedirect3()
        {
            // this time with HTTPBehavior
            // make sure we were redirected and no exception is thrown
            HttpClient client = new HttpClient();
            HttpBehavior httpBehavior = new HttpBehavior();
            httpBehavior.AddStep(302, Constants.HTTP_REDIRECT_TARGET_1);
            httpBehavior.AddStep(200);
            HttpGet getMethod = new HttpGet(new Uri(Constants.HTTP_GET_302));
            HttpResponse response = client.Execute(getMethod, httpBehavior);

            Assert.AreEqual(200, response.ResponseCode);
            Assert.AreEqual(Constants.HTTP_REDIRECT_TARGET_1, response.RequestUri.AbsoluteUri);
            string responseString = EntityUtils.ToString(response.Entity);
            Console.Write(responseString);
        }
        public void HttpGetWithRedirect4()
        {
            // this time with HTTPBehavior
            // here both response code and location are wrong
            // make sure an exception is thrown

            HttpClient client = new HttpClient();
            HttpBehavior httpBehavior = new HttpBehavior();
            httpBehavior.AddStep(200);
            HttpGet getMethod = new HttpGet(new Uri(Constants.HTTP_GET_302));
            HttpResponse response = client.Execute(getMethod, httpBehavior);
        }
        public void HttpGetWithRedirect7()
        {
            // this time with HTTPBehavior
            // make sure we get only the first response
            // and do not make the second call
            HttpClient client = new HttpClient();
            HttpBehavior httpBehavior = new HttpBehavior();
            httpBehavior.AddStep(302, Constants.HTTP_REDIRECT_TARGET_1);
            HttpGet getMethod = new HttpGet(new Uri(Constants.HTTP_GET_302));
            HttpResponse response = client.Execute(getMethod, httpBehavior);

            Assert.AreEqual(302, response.ResponseCode);
            Assert.AreEqual(Constants.HTTP_REDIRECT_TARGET_1, response.Location);
        }