excel - 如何将 curl cammand 转换为 vba (winHttprequest)?
问题描述
我想向 API(条带)发送请求。我想将 curl 转换为 winhttp 请求...我找不到任何执行此操作的说明。这是我尝试的,但我收到错误
Public Sub SendThePostExample()
Dim BaseUrl As String
Dim JBody As String
Dim HReq As New WinHttp.WinHttpRequest
Dim HRes As String
JBody = "{""description"" : ""testing""}"
BaseUrl = "https://api.stripe.com/v1/customers"
HReq.Open "POST", BaseUrl, True
HReq.SetRequestHeader "Content-Type", "application/json"
HReq.SetRequestHeader "Authorization", "Bearer " & "APISecretKey"
HReq.Send (JBody)
HReq.WaitForResponse
HRes = HReq.ResponseText
Debug.Print HRes
MsgBox HRes
Set HReq = Nothing
End Sub
我要转换为 httpReq 的这个 curl 代码:
curl https://api.stripe.com/v1/customers \
-u API Secret Key: \
-d description="Customer for jenny.rosen@example.com" \
-d source=tok_visa
我收到的错误:
{
"error": {
"message": "Invalid request (check that your POST content type is application/x-www-form-urlencoded). If you have any questions, we can help at https://support.stripe.com/.",
"type": "invalid_request_error"
}
}
解决方案
推荐阅读
- node.js - Oauth2 Flow , Authorize 和 Authorization Grant 的区别
- android - 如何分析 btsnoop_hci.log (bluetooth/android/wireshark)
- mql4 - 重新 MQL4 代码限制打开符号的数量
- php - 在 PHP 中的 zoho api v2 中插入记录
- postgresql - Postgres - UNION ALL 与 INSERT INTO 哪个更好?
- php - 在 PHP 如何更新下拉列表值
- wordpress - Woocommerce 产品类别模板
- swift - “尚未配置默认的 Firebase 应用程序” - Swift
- python - Python程序在UI操作后等待并继续
- python - python请求无法下载zip文件,而浏览器/硒可以