문제

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!)

도움이 되었습니까?

해결책 2

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

다른 팁

The only way I know of to find which URL it redirects to is by making the request and reading the response.

request1.GetResponse().Headers("Location")

FYI: You should check out Fiddler. It's a free app that will allow you to visually inspect the requests and responses made by your browser. You can copy paste that link you have into your browser and see what the server says back. Then you'll know which Header to check for the info you want.

Hope that helps.

Try This,

Dim req As HttpWebRequest = DirectCast(HttpWebRequest.Create("http://tinyurl/ajdeijad"), HttpWebRequest)
Dim response As HttpWebResponse
Dim resUri As String
response = req.GetResponse
resUri = response.ResponseUri.AbsoluteUri
MsgBox(resUri)

This will return the redirected URL.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top