C#使用HttpClient获取Location

之前使用HttpWebRequest的时候,只需要设置HttpWebRequest对象的AllowAutoRedirect属性值为false即可在Respomse的Header中获取Location;

但是后来在SilverLight中使用HttpWebRequest的时候,没有AllowAutoRedirect这个属性了,各种点也点不出来,于是只能用HttpClient 了,代码如下:

 public string GetLocation(string URL)
{
HttpClientHandler hander = new HttpClientHandler();
hander.AllowAutoRedirect = false;
HttpClient client = new HttpClient(hander);
return client.GetAsync(URL).Result.Headers.Location.ToString();
}

引用名词空间System.Net.Http

上一篇:What can Reactive Streams offer EE4J?


下一篇:Android 9 适配怎么做? “QQ音乐”优化实录