gpt4 book ai didi

json - 如何使用 VBScript 通过 HTTP API POST JSON 数据?

转载 作者:行者123 更新时间:2023-12-04 05:38:23 29 4
gpt4 key购买 nike

尝试将 JSON POST 请求发送到 HTTP API(PushBullet)。但面临代码中的错误。任何帮助表示赞赏。 Reference to the document to send push notification

Dim objXmlHttpMain , URL

strJSONToSend = {"type": "note", "title": "Alert", "body": "Lorem Ipsum Lorem Ipsum Lorem Ipsum."}

URL="https://api.pushbullet.com/v2/pushes"
Set objXmlHttpMain = CreateObject("Msxml2.ServerXMLHTTP")
on error resume next
objXmlHttpMain.open "POST",URL, False
objXmlHttpMain.setRequestHeader "Authorization", "Bearer <api secret id>"
objXmlHttpMain.setRequestHeader "Content-Type", "application/json"


objXmlHttpMain.send strJSONToSend

set objJSONDoc = nothing
set objResult = nothing

最佳答案

在这里冒险,因为您认为没有必要包含实际的错误消息。您很可能在第 3 行收到“无效字符”错误。那是因为您需要将 JSON 字符串定义为实际字符串。

改变这个:

strJSONToSend = {"type": "note", "title": "Alert", "body": "Lorem Ipsum Lorem Ipsum Lorem Ipsum."}

进入这个:
strJSONToSend = "{""type"": ""note"", ""title"": ""Alert"", ""body"": ""Lorem Ipsum Lorem Ipsum Lorem Ipsum.""}"

编辑:作为旁注,如果您使用 On Error Resume Next在您的代码中始终放置适当的错误处理,并尽可能使其本地化:
On Error Resume Next   'enable error handling
objXmlHttpMain.open "POST",URL, False
If Err Then 'handle errors
WScript.Echo Err.Description & " [0x" & Hex(Err.Number) & "]"
WScript.Quit 1
End If
On Error Goto 0 'disable error handling again

关于json - 如何使用 VBScript 通过 HTTP API POST JSON 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26956256/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com