需要vbscript才能找到输入网址的重定向页面的URL

时间:2018-04-06 15:25:33

标签: url redirect vbscript

我有Text个网址作为输入。在Web浏览器中打开时,立即打开一个弹出屏幕,有两种可能性 - 一个。弹出屏幕将显示带有http:\\URL_MAIN网址的网页 湾弹出屏幕将显示包含http:\\URL_SUCCESS

的网页

我需要一个vbscript,我可以在其中输入http:\\URL_FAILURE,作为回报,它应该告诉我它在弹出屏幕中重定向到哪个URL。在这方面的任何帮助将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

这个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
'**************************************************************