如何在请求后以字符串形式获取重定向的网址

发布于 2024-12-18 18:47:33 字数 464 浏览 3 评论 0原文

例如,在任何tinyurl/ajdeijad链接(这个是假的)上,think重定向到另一个url

这是我的代码:

    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

如何检索响应的url(它重定向!)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

唱一曲作罢 2024-12-25 18:47:33

简单 - 只需获取响应的 reponseuri 即可!

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

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

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
情愿 2024-12-25 18:47:33

我知道找到它重定向到的 URL 的唯一方法是发出请求并读取响应。

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

仅供参考:您应该查看 Fiddler。它是一个免费的应用程序,可让您直观地检查浏览器发出的请求和响应。您可以将该链接复制粘贴到浏览器中,然后查看服务器返回的内容。然后你就会知道要检查哪个标题来获取你想要的信息。

希望有帮助。

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.

病女 2024-12-25 18:47:33

试试这个,

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)

这将返回重定向的 URL。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文