之前使用HttpWebRequest的时候,只需要设置HttpWebRequest对象的AllowAutoRedirect属性值为false即可在Respomse的Header中获取Location;
但是后来在SilverLight中使用HttpWebRequest的时候,没有AllowAutoRedirect这个属性了,各种点也点不出来,于是只能用HttpClient 了,代码如下:
1 public string GetLocation(string URL) 2 { 3 HttpClientHandler hander = new HttpClientHandler(); 4 hander.AllowAutoRedirect = false; 5 HttpClient client = new HttpClient(hander); 6 return client.GetAsync(URL).Result.Headers.Location.ToString(); 7 }
引用名词空间System.Net.Http
时间: 2024-10-14 06:51:22