码迷,mamicode.com
首页 > Windows程序 > 详细

C#使用HttpClient获取Location

时间:2017-02-19 11:04:58      阅读:379      评论:0      收藏:0      [点我收藏+]

标签:net   url   new   pom   return   pre   turn   dir   request对象   

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

C#使用HttpClient获取Location

标签:net   url   new   pom   return   pre   turn   dir   request对象   

原文地址:http://www.cnblogs.com/yh2015/p/6414773.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!