【问题标题】:Need vbscript to find out redirected page's URL for an input URL需要 vbscript 来找出输入 URL 的重定向页面的 URL
【发布时间】:2018-04-06 15:25:33
【问题描述】:

我有http:\\URL_MAIN url 作为输入。这在网络浏览器中打开时,会立即打开一个弹出屏幕,有两种可能性 - 一种。任一弹出屏幕都将显示带有http:\\URL_SUCCESS url 的网页或 湾。弹出屏幕将显示带有http:\\URL_FAILURE的网页

我需要一个 vbscript,我可以在其中输入我的http:\\URL_MAIN,作为回报,它应该在弹出屏幕中告诉我它重定向到哪个 URL。非常感谢您在这方面的任何帮助。

【问题讨论】:

标签: url redirect vbscript


【解决方案1】:

这个 vbscript 可以做到这一点:

Option Explicit
Dim strUrl,Title
Title = "Get Header Location"
Do  
    strUrl = InputBox("Copy and paste your link here to get the response header",_
    Title,"http://www.vbfrance.com/")
    If Len(strUrl) = 0 Then 
        Exit Do
    Else 
        MsgBox GetHeaderLocation(strUrl),vbExclamation,Title
    End if
Loop Until IsEmpty(strUrl)  
wscript.Quit()
'**************************************************************
Function GetHeaderLocation(strUrl)
    On Error Resume Next
    Const WHR_EnableRedirects = 6
    Dim oHttp,Target
    Set oHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
    oHttp.Option(WHR_EnableRedirects) = False
    oHttp.Open "HEAD", strUrl, False
    oHttp.send
    If Err.Number = 0 Then
        If oHttp.Status = 200 Then
            Target = "There is no redirection " &_
            oHttp.Status & " " & oHttp.statusText & vbcrlf &_
            "for this URL : " & chr(34) & strUrl & chr(34)
        ElseIf oHttp.Status = 301 Or oHttp.Status = 302 Then
            Target = "This URL is redirected to : " & vbCrlf &_
            chr(34) & oHttp.getResponseHeader("Location") & chr(34)
        End If
    Else
        GetHeaderLocation = "Error " & Err.Number & vbCrlf &_
        Err.Source & " " & Err.Description
    End If
    GetHeaderLocation = Target
End Function
'**************************************************************

【讨论】:

    猜你喜欢
    • 2013-09-14
    • 2020-11-12
    • 2020-02-27
    • 2019-06-07
    • 2010-09-24
    • 2014-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多