Visual Basic 将数据作为 json 对象发送到 api

编程入门 行业动态 更新时间:2024-10-27 20:27:56
本文介绍了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:关键词]

本文发布于:2023-04-18 13:35:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/938515.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   对象   数据   Visual   Basic

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!