Trying to integrate an HTTP GET request in my MS-Access database program

前端 未结 3 1582
挽巷
挽巷 2021-01-24 09:55

I want to import data from Anedot, a credit card processing firm, using a HTTP GET request from an MS Access program. Anedot uses a RESTful API and has provided help on there we

3条回答
  •  被撕碎了的回忆
    2021-01-24 10:46

    It's a fairly lengthy question to be honest, but lets start with some code to get you going.

    This Class Module ("clsXMLHttpMonitor") should help:

    Option Explicit
    
    
    Dim XMLHttpReq As MSXML2.ServerXMLHTTP
    
    Dim RequestedVar As String
    Dim P As Object
    
    Public Sub Initialize(ByVal uXMLHttpRequest As Object, Optional RequestedValue As String = "")
       RequestedVar = RequestedValue
       Set XMLHttpReq = uXMLHttpRequest
    End Sub
    
    Sub ReadyStateChangeHandler()
        If XMLHttpReq.ReadyState = 4 Then
            If XMLHttpReq.Status = 200 Then
                'Process the response here
                Debug.Print "200 recieved"
                Set P = JSON.parse(XMLHttpReq.responseText)
            Else
                If XMLHttpReq.Status = 404 Then
                    'Handle it
                End If
            End If
        End If
    
    End Sub
    
    Function returnResponseHeaders() As String
    returnResponseHeaders = XMLHttpReq.getAllResponseHeaders
    XMLHttpReq.Send
    End Function
    
    Function returnFullText() As String
    If XMLHttpReq.ReadyState = 4 Then
        If XMLHttpReq.Status = 200 Then
            returnFullText = XMLHttpReq.responseText
        Else
            returnFullText = "-1"
        End If
    Else
        returnFullText = ""
    End If
    End Function
    
    End Function
    

    Use it like this:

    Set XMLHttpReq = New MSXML2.ServerXMLHTTP
    Set XMLHttpMon = New clsXMLHttpMonitor
    XMLHttpMon.Initialize XMLHttpReq
    XMLHttpReq.OnReadyStateChange = XMLHttpMon
    XMLHttpReq.Open "POST", URL, True
    XMLHttpReq.Send strPayload
    

提交回复
热议问题