2013-03-13 40 views

回答

1

這工作:

'http://tinyurl.com/gtrp -> points to google.ca 
Dim urls As List(Of String) = GetAllRedirectURLs("http://tinyurl.com/gtrp") 
'urls(0) = "http://google.ca" 
'urls(1) = "http://www.google.ca/" 

Private Function GetAllRedirectURLs(path As String) As List(Of String) 
    Dim urls As New List(Of String) 
    Dim request As HttpWebRequest = WebRequest.Create(path) 
    request.Method = "HEAD" 
    request.AllowAutoRedirect = False 
    Dim response As HttpWebResponse = request.GetResponse 
    If response.StatusCode = HttpStatusCode.Moved Or response.StatusCode = HttpStatusCode.Redirect Then 
    Dim redirectsToURL As String = response.GetResponseHeader("Location") 
    urls.Add(redirectsToURL) 
    urls.AddRange(GetAllRedirectURLs(redirectsToURL)) 
    End If 
    Return urls 
End Function 

使用遞歸向下鑽取和收集的鏈接。基於this question

+0

這很好用..感謝@Neolisk .. – bharat1010 2013-03-14 08:41:46