【问题标题】:How To Get The Redirected URL From Original URL Visual Basic .NET如何从原始 URL Visual Basic .NET 中获取重定向的 URL
【发布时间】:2012-11-17 07:42:03
【问题描述】:

如何从原始 URL 或短 URL 获取重定向 URL?

例如:

    URL_1 (Short URL) = "http://af.ly/FQhAo"

这将重定向到

    URL_2 (Original URL) = "http://download.bitdefender.com/windows/desktop/t_security/2013/en-us/bitdefender_ts_2013_32b.exe"

那么我们如何从 URL_1 获取 URL_2 呢?请帮忙。 (我搜索过但没有找到任何解决方案)

项目信息:

  • 平台:Visual Basic Express 2010
  • .NET 框架版本:2.0

感谢您的宝贵时间。 已编辑:

我只有一个 URL,即 URL_1,我想借助 URL1 获取 URL_2。

见下图,著名软件如何立即从 URL_1(短 URL 和已知字符串)获取 URL_2(100% 未知字符串)。我想在我的 Visual Basic .net 程序中做同样的事情。

【问题讨论】:

    标签: vb.net vb.net-2010 url-redirection


    【解决方案1】:

    感谢 google 和 Daniweb,我的问题现已解决 这是解决方案

    Dim req As HttpWebRequest = DirectCast(HttpWebRequest.Create("Your short URL here"), HttpWebRequest)
            Dim response As HttpWebResponse
            Dim resUri As String
            response = req.GetResponse
            resUri = response.ResponseUri.AbsoluteUri
            MsgBox(resUri)
    

    这将返回 URL_2。

    【讨论】:

    • 只有我一个人还是那一行写着Dim Res As HttpWebResponse = req.GetResponse() 多余且未使用?
    • req.GetResponse() 在响应之后使用 = req.GetResponse
    • 你可以简化这个:Dim resUri As String = DirectCast(WebRequest.Create("url here"), HttpWebRequest).GetResponse.ResponseUri.AbsoluteUri
    【解决方案2】:

    为什么不将原始 URL 作为查询字符串参数传递?即在 url_1 中,重定向到:http://pastehtml.com/view/b95qx66rc.html?redirectfrom=http://goo.gl/ouCeb

    然后在 url_2 中使用以下代码:

    Dim OriginalURL As String = request.querystring("redirectfrom")
    

    【讨论】:

    • Dim OriginalURL As String = request.querystring("redirectfrom") 错误:“请求未声明。” 我只知道 URL_1,我想借助 URL_1 知道 URL_2。
    • 我添加了一张图片,这有助于您理解我的问题。 @w0051977
    【解决方案3】:

    URL_2 = "http://" & URL_1 & "/view/b95qx66rc.html"

    【讨论】:

    • 噢噢噢!!!正如我所说的我什至不知道 URL_2 的一个字母,所以我从哪里得到“/view/b95qx66rc.html”?这不是解决方案,我认为解决方案是 HTTPrequest 但如何?
    • 我添加了一张图片,这有助于您理解我的问题。 @iDev
    猜你喜欢
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 2022-09-25
    • 1970-01-01
    • 1970-01-01
    • 2011-01-18
    相关资源
    最近更新 更多