lundi 7 décembre 2020

How to get the resulting URL from MSXML2.ServerXMLHTTP

I'm using MSXML2.ServerXMLHTTP to get the resulting text or error from a web-site. The web-site does a redirect. How do I get the value of the new URL?

Class RemoteHTML Private httpObject As Variant Public httpStatus As Integer

Public Sub New()
    Set httpObject = CreateObject("MSXML2.ServerXMLHTTP")
End Sub

Public Function GetHTTP(httpURL As String) As String
    Dim retries As Integer
    Dim tmp As string
    retries = 0     
    Do
        If retries>1 Then
            Sleep 1     ' After the two first calls, introduce a 1 second delay betwen each additional call
        End If
        retries = retries + 1   
        Call httpObject.open("GET", httpURL, False)
        Call httpObject.send()
        httpStatus = httpObject.Status
        If retries >= 10 Then
            httpStatus = 0  ' Timeout
        End If
    Loop Until httpStatus = 200 Or httpStatus > 500 Or httpStatus = 404  Or httpStatus = 0
    'If httpStatus = 200 Then
        GetHTTP = Left$(httpObject.responseText,16000)
        tmp = httpobject.URL
    'Else
    '    GetHTTP = ""
    'End If
End Function



Aucun commentaire:

Enregistrer un commentaire