gpt4 book ai didi

json - 在 VBA 中发送 JSON POST 请求

转载 作者:行者123 更新时间:2023-12-04 20:32:25 25 4
gpt4 key购买 nike

我有以下 JSON POST 示例代码,我正在尝试将其转换为 Excel 的 VBA:

POST /services/shipper/orders HTTP/1.1
Content-Type: application/json
User-Agent: Mozilla 5.0
Host: qa.etowertech.com
X-WallTech-Date: Tue, 06 Jan 2018 21:20:27 GMT
Authorization: WallTech test5AdbzO5OEeOpvgAVXUFE0A:79db9e5OEeOpvgAVXUFWSD

这是我想出的代码:
With JsonHTTP
.Open "POST", "http://qa.towertech.com/services/shipper/orders", False
.setRequestHeader "RequestName", "application/json"
.setRequestHeader "Accept", "application/json"
.setRequestHeader "User-Agent", "Mozilla 5.0"
.setRequestHeader "Host", "qa.etowertech.com"
.setRequestHeader "X-WallTech-Date", "Tue, 06 Jan 2018 21:20:27 GMT"
.setRequestHeader "Authorization", "WallTech test5AdbzO5OEeOpvgAVXUFE0A:79db9e5OEeOpvgAVXUFWSD"
.send (body)
End With

我不确定 POST /services/shipper/orders HTTP/1.1 在哪里输入应该去

我不断收到这样的回复:
{
"status": "Failed",
"errors": [
{
"code": 100004,
"message": "System internal error"
}
],
"data": null
}

编辑:

我得到的当前响应:
{
"status": "Failed",
"errors": [
{
"code": 401,
"message": "Authorization information is invalid."
}
],
"data": null
}

我只是想我错过了签名(请参阅下面的说明),但不确定如何呈现它以及它在请求中的确切位置?

X-WallTech-日期
EEE, dd MMM yyyy HH:mm:ss zzz

授权
WallTech <Access Token>:<Base64 Encoded HMAC SHA-1 Hash>

签名字符串
<HTTP Verb> + "\0x000A" + <X-WallTech-Date Header> + "\0x000A" + <Full URL>

最佳答案

这是解决方案:

url = "http://qa.towertech.com/services/shipper/orders"
token = "xxxxxx" ' API token goes here
auth = Base64_HMACSHA1("POST" & Chr(10) & timestamp & Chr(10) & url, key)

With JsonHTTP
.Open "POST", url, False
.setRequestHeader "RequestName", "application/json"
.setRequestHeader "Accept", "application/json"
.setRequestHeader "User-Agent", "Mozilla 5.0"
.setRequestHeader "Host", "qa.etowertech.com"
.setRequestHeader "X-WallTech-Date", timestamp
.setRequestHeader "Authorization", "Walltech " & token & ":" & auth
.send (body)
End With

问题是 Base64 函数中缺少 key ,因此验证字符串被错误编码

希望这可以帮助其他有同样情况的人!

关于json - 在 VBA 中发送 JSON POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48133663/

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