本文介绍了Visual Basic 将数据作为 json 对象发送到 api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..美好的一天,我正在尝试将数据作为 json 对象发送到 api
Good day i am try to sent data to api as json object like that
"Content-Type: application/json"
"Authorization: Bearer $ACCESS_TOKEN"
-d '[
{
"datetime": "2021-02-21 14:07:37",
"isRefund": false,
"receiptNumber": "880090",
"amount": 164.22
}
]'
这是我的代码:
Sub X2()
' Dim xhr As Object
Set xhr = CreateObject("MSXML2.ServerXMLHTTP")
xhr.Open "POST", "https://tenanttest.api.rubixpark/api/v1/sales", False
xhr.setRequestHeader "Content-Type", "application/json"
xhr.setRequestHeader "Authorization", "Bearer " + accesstoken
xhr.setRequestHeader "datetime", Now()
xhr.setRequestHeader "isRefund", False
xhr.setRequestHeader "receiptNumber", 111
xhr.setRequestHeader "amount", Format(1000#, "##,##0.00")
xhr.send
If xhr.Status = 200 Then
MsgBox xhr.ResponseText
Else
End If
End Sub
所以我只想将访问令牌发送到标题和正文中的其他数据作为 json 对象,如第一个代码块任何帮助和感谢
so i would like to sent access token only on header and other data on body as json object like first block of code any help and thanks
推荐答案
看起来像这样:
Dim xhr As Object
Set xhr = CreateObject("MSXML2.ServerXMLHTTP")
xhr.Open "POST", "https://tenanttest.api.rubixpark/api/v1/sales", False
xhr.setRequestHeader "Content-Type", "application/json"
xhr.setRequestHeader "Authorization", "Bearer " + accesstoken
xhr.send "[{""datetime"": ""2021-02-21 14:07:37"",""isRefund"": false," & _
"""receiptNumber"": ""880090"",""amount"": 164.22}]"
If xhr.Status = 200 Then
MsgBox xhr.ResponseText
End If
这篇关于Visual Basic 将数据作为 json 对象发送到 api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论