win8 HttpClient自动重定向

时间:2013-04-23 02:01:05

标签: windows microsoft-metro

当我使用HttpClient.GetAsync(url)时,但是url不是可访问的地址,但它总是重定向到另一个地址,并且它返回一个带有ok的statuecode。

var httpClient = new HttpClient(handler);
        httpClient.DefaultRequestHeaders.ExpectContinue = false;
        //using ()
        {
            HttpResponseMessage response = new HttpResponseMessage();
            response = await httpClient.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                var result = response.Content.ReadAsStringAsync();
                Debug.WriteLine(response.StatusCode.ToString());
            }
            else
            {
                // problems handling here
                Debug.WriteLine(
                    "Error occurred, the status code is: {0}",
                    response.StatusCode
                );
            }
        }

0 个答案:

没有答案