VBA Post Request to an API in MS Access vba



  • Hello,
    I am trying to make a post request using the below code. curl is working perfectly however, the post request code i wrote is not working.

    Public Sub getscholar()

    Dim webServiceURL As String
    Dim actionType As String
    Dim targetWord As String
    Dim actionType2 As String
    Dim targetWord2 As String

    webServiceURL ="http://ktsstf.org/call.phpapicall=registration.data&apiDataType=xml"
    actionType = "Content-Type"
    targetWord = "text/xml"
    actionType2 = "Authorization"
    'targetWord2 = "apikey" + "d8a40f77-69b5-4ef7-b554-d8f86382101c"
    targetWord2 = "Basic " & ("d8a40f77-69b5-4ef7-b554-d8f86382101c")

    ' use late binding
      With CreateObject("Microsoft.XMLHTTP")
        .Open "POST", webServiceURL, False
        .setRequestHeader actionType, targetWord
        .setRequestHeader actionType2, targetWord2
        .send
        If .Status = 200 Then
          Debug.Print .responseText
          MsgBox .GetAllResponseHeaders
        Else
          MsgBox .Status & ": " & .StatusText
        End If
      End With
    

    End Sub



  • this is how i access the api through curl

    curl -F "apikey=d8a40f77-69b5-4ef7-b554-d8f86382101c" "https://ktsstf.org/call.php?apicall=registration.data&apiDataType=xml"


Log in to reply
 

Looks like your connection to Codingislove Forum was lost, please wait while we try to reconnect.