之前使用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

相关文章:

  • 2022-12-23
  • 2021-05-31
  • 2021-06-22
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
猜你喜欢
  • 2022-01-06
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案