Perform hidden http-request from vba

2019-08-13 03:35发布

问题:

I want to perform a hidden HTTP-GET request from MS-access, as simple as possible, without any extra libraries/components.

Just a simple declare all needed.

Has WinHttp left the building??

回答1:

Here is a great page about that.



回答2:

Hope this helps

 Dim xhr As Object
 Dim webServiceURL As String
 Dim actionType As String
 Dim thisRequest As String
 Dim targetWord As String

 WebServiceURL = "http://services.aonaware.com/DictService/DictService.asmx/"
 actionType = "Define?word="
 targetWord = "Marketplace"
 thisRequest = webServiceURL & actionType & targetWord

 'use late binding
 Set xhr = CreateObject("Microsoft.XMLHTTP")  

 xhr.Open "GET", thisRequest, False
 xhr.Send

 If xhr.status = 200 Then
   Debug.Print xhr.responseText
   MsgBox xhr.getAllResponseHeaders
 Else
   MsgBox xhr.status & ": " & xhr.statusText
 End If

 Set xhr = Nothing