c# 获取百度最后的url

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

 

namespace getBaiDuUrl
{
class Program
{
static void Main(string[] args)
{
string LastAdurl= GetLocation("http://www.baidu.com/link?url=MW4aqBcVd9VSAsqrVcG8lMzlHUU1qWjFsD_PxZNEjJlxE1sNpirSITeWwcBgcGQ8");
}
public static string GetLocation(string URL)
{
HttpClientHandler hander = new HttpClientHandler();
hander.AllowAutoRedirect = false;
HttpClient client = new HttpClient(hander);
return client.GetAsync(URL).Result.Headers.Location.ToString();
}
}
}

 

posted @ 2017-07-25 09:01  公众号python学习开发  阅读(685)  评论(0编辑  收藏  举报