Web库可在VBA中处理JSON调用:
https://github.com/VBA-tools/VBA-Web
这是Postman中的通话,效果很好:
curl -X GET \
https://<URL>/ \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Postman-Token: dee67429-d5f8-45fd-8004-f5c244729526' \
-H 'cache-control: no-cache' \
-d 'api_key=<Key>'
我在Access中苦苦挣扎,以使VBA-Web代码正常工作。这是我编写的代码:
Dim Client As New WebClient
Dim Request As New WebRequest
Dim Response As WebResponse
Dim Body As New Dictionary
Client.BaseUrl = "https:<URL>"
Request.Method = WebMethod.HttpGet
Request.ContentType = "application/x-www-form-urlencoded"
Request.AddBodyParameter "api_key", "<Key>"
Set Response = Client.Execute(Request)
似乎响应API,因为内容响应为“ {“错误”:“无效请求”}“。有什么想法让我误入歧途吗?请注意,在此调用中,不需要任何Request.Resource,因为它在根级别。他们还有其他API处于下一层。
谢谢!