在VBA中发送JSON POST请求

编程入门 行业动态 更新时间:2024-10-27 20:38:25
本文介绍了在VBA中发送JSON POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I have the following JSON POST sample code which I am trying to convert to VBA for Excel:

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

这是我想出的代码:

With JsonHTTP .Open "POST", "qa.towertech/services/shipper/orders", False .setRequestHeader "RequestName", "application/json" .setRequestHeader "Accept", "application/json" .setRequestHeader "User-Agent", "Mozilla 5.0" .setRequestHeader "Host", "qa.etowertech" .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输入应该放在哪里

I wasn't sure where the POST /services/shipper/orders HTTP/1.1 input should go

我一直收到以下答复:

{ "status": "Failed", "errors": [ { "code": 100004, "message": "System internal error" } ], "data": null }

我得到的当前答复:

{ "status": "Failed", "errors": [ { "code": 401, "message": "Authorization information is invalid." } ], "data": null }

我只是认为我错过了签名(请参见下面的说明),但是不确定如何渲染它以及它在请求中的确切位置?

I just figured I missed out on the Signature (see below instruction) but wasn't sure how to render it and where it goes exactly in the request?

X-WallTech-Date

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 = "qa.towertech/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" .setRequestHeader "X-WallTech-Date", timestamp .setRequestHeader "Authorization", "Walltech " & token & ":" & auth .send (body) End With

问题是Base64函数缺少密钥,因此auth字符串编码不正确

The problem was the secret key was missing from the Base64 function so the auth string was incorrectly encoded

希望这可以帮助其他任何人拥有相同的东西!

Hope this helps anyone else having the same!

更多推荐

在VBA中发送JSON POST请求

本文发布于:2023-10-10 12:19:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1478650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:VBA   JSON   POST

发布评论

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

>www.elefans.com

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