Search code examples
.nethttpwebrequestwebresponse

How to get redirected url as string after request


For example on any tinyurl/ajdeijad link (this one is fake), the think redirects to another url

Here is my code:

    Dim request1 As HttpWebRequest = DirectCast(HttpWebRequest.Create(urlvimeohd), HttpWebRequest)
            request1.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1"
            request1.MaximumAutomaticRedirections = 1
            request1.AllowAutoRedirect = True

How do you retrieve the url of the response (it redirects!)


Solution

  • Simple - just get the reponseuri of the response!

    http://msdn.microsoft.com/en-us/library/system.net.webresponse.responseuri.aspx

    dim myresponse as request1.getresponse()
    dim x as string = myresponse.ResponseURI