我必须通过VBA发送json帖子。这是一个示例帖子:
curl\
-d '{"@SOURCE":"A1","@DESTINATION":"B1","apikey":"SDFLIEJLE....DLKFJSLKDJF"}'\
-H "Content-Type: application/json"\
-X POST https://12345678.net:8443/workflow/0
我知道,我已经在VBA中使用了WinHttpRequest。但是我不知道如何以正确的方式将帖子与sub合并。这里是WinHttpRequest的示例子:
Sub PostJSON()
Dim URL As String
Dim JSONString As String
Dim objHTTP As New WinHttpRequest
URL = "https://api.knack.com/v1/objects/object_1/records"
objHTTP.Open "POST", URL, False
objHTTP.SetRequestHeader "X-Knack-Application-Id", "######"
objHTTP.SetRequestHeader "X-Knack-REST-API-KEY", "######"
objHTTP.SetRequestHeader "Content-Type", "application/json"
JSONString = "{""field_1"":""1 Smith St, Smithville""}"
objHTTP.Send JSONString
End Sub
我不了解Microsoft文档。 https://docs.microsoft.com/en-us/windows/win32/winhttp/winhttprequest
非常感谢您的帮助。
最诚挚的问候
亚历山大
Sub PostJSON()
Dim URL As String
Dim JSONString As String
Dim objHTTP As New WinHttpRequest
URL = "https://12345678.net:8443/workflow/0"
objHTTP.Open "POST", URL, False
objHTTP.SetRequestHeader "Content-Type", "application/json"
JSONString = "{""@SOURCE"":""A1"",""@DESTINATION"":""B1"", ""apikey"":""SDFLIEJLE....DLKFJSLKDJF""}"
objHTTP.Send JSONString
'typically here you would check the response to make sure
' the post was successfull....
End Sub