所以我有这个程序,使用一个简短的链接(我使用谷歌URL缩短)获取一个页面。 要建立我的例子中我使用了Using WebClient in C# is there a way to get the URL of a site after being redirected?C#WebClient OpenRead url
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
MyWebClient client = new MyWebClient();
client.OpenRead("http://tinyurl.com/345yj7x");
Uri uri = client.ResponseUri;
Console.WriteLine(uri.AbsoluteUri);
Console.Read();
}
}
class MyWebClient : WebClient
{
Uri _responseUri;
public Uri ResponseUri
{
get { return _responseUri; }
}
protected override WebResponse GetWebResponse(WebRequest request)
{
WebResponse response = base.GetWebResponse(request);
_responseUri = response.ResponseUri;
return response;
}
}
}
代码我不understant一件事:当我做这个client.OpenRead("http://tinyurl.com/345yj7x");
下载页面的URL指向?如果这种方法下载页面,我需要一些东西来让我只有网址,所以如果有一种方法只获得一些标题,或只有网址,请让我知道。
舷窗。然后,只需使用response.ResponseUri来获取您的网址 - 在这种情况下,它看起来是“http://www.google.ro/search?sourceid=chrome&ie=UTF-8&q=c%23+webclient+tinyurl” – Reddog 2010-12-22 10:13:18