vba - VBA 将 Xmlhttp 对象作为 x-www-form-urlencoded 发送
问题描述
我想将我的 Excel 与 eBay API 连接起来。对于Access Token Workflow,我需要在那里刷新我的令牌。在邮递员中,我实现了工作流程,但将请求正文转换为 VBA 时遇到问题。
eBay 需要Content Type
is application/x-www-form-urlencoded
,它在请求标头中设置。如果我使用 Postman 和编码为 的正文进行 POST,x-www-form-urlencoded
则可以成功访问 API。
请求标头只有 Authorization 和Content-Type
. 这是 Postman 中的 Body Settings 的图像:
如果我在这里使用原始正文执行 Postman API-POST:
grant_type=refresh_token&code=v^1.XXXXXX_HIDDEN_XXXXXFXjI2MA==&scope=https://api.ebay.com/oauth/api_scope
...然后我得到回应:
"error": "invalid_grant",
"error_description": "the provided authorization refresh token is invalid or was issued to another client"
对于 VBA,我需要发送一个原始正文(我无法解决的问题,就像我展示的那样),或者我需要将发送输入设置为x-www-form-urlencoded
,但我也没有办法这样做。
这是我的 VBA 代码,它给了我一个错误,说它格式错误:
Set objHTTP = CreateObject("Microsoft.xmlhttp")
objHTTP.Open "POST", "https://api.ebay.com/identity/v1/oauth2/token", False
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.setRequestHeader "Authorization", "Basic XXXHIDDENXXXX"
objHTTP.Send ("grant_type=authorization_code&code=xxHIDDENxx&scope=https://api.ebay.com/oauth/api_scope")
answer = objHTTP.responseText
MsgBox answer
这里是 VBA 错误:
{"error":"invalid_request", "error_description":"request is missing a required parameter or malformed."}
解决方案
推荐阅读
- uwp - 无法通过 Appium 脚本打开我的应用程序
- android - 推荐的方法/API 来设计具有 N 到 M 连接的多用户 Android 应用程序?
- unity3d - 使用 ARCore 和 Unity 显示 PNG 或图像
- c# - 防止 Web API 中多个数据库调用发生冲突
- java - 获取数据时出现 OutOfBoundsException
- highcharts - 在 Highchart 中,如何更改多轴图表中所有图例符号的高度?
- elasticsearch - ElasticSearch - 按特定字段删除文档
- python - lxml:具有节点相同元素的while循环
- amazon-web-services - 将与模式匹配的 Cloudwatch 日志发送到 SQS 队列
- python - 将数据库中的列与python代码中获取的变量进行比较