首页 > 解决方案 > 如何将 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"
  }
}

标签: excelvbaapicurlhttps

解决方案


推荐阅读