none
How to capture the last URL from bunch of redirected URLs RRS feed

  • Question

  • Hi,

    I am trying to capture the last URL from a bunch of redirected URLs using excel VBA. Can someone please help.

    Here is my code. 

    Function GetURL(url As String)
        Dim request As New WinHTTP.WinHttpRequest
        request.Option(WinHttpRequestOption_EnableRedirects) = True
        request.Open "HEAD", url, False
        request.Send
        If Not request.Option(1) = "" Then
            GetURL = request.Option(1)
        Else
            GetURL = url
        End If
    End Function

    This code only returns the first redirected URL. I am not sure what did I miss.

    Example:

    http://example.com redirects to http://www.example.com redirects to https://www.example.com

    GetURL("http://example.com") gives result -- http://www.example.com

    Desired result is https://www.example.com

    Friday, March 31, 2017 4:55 AM

All replies