如何在VBA HTTP API中使用-x进行POST?

问题描述 投票:0回答:2

我有一堆对STRIPE的API调用,这些调用都很好用.通常我使用cURL版本,并找出我需要做的事情。

我刚刚遇到了需要删除一个订阅的情况。

   curl https://api.stripe.com/v1/subscriptions/sub_FpZkRarex4obNX \
  -u sk_test_VHkTM0bOtpsE1dBnTxFbMBAk00WnBQnyI5: \
  -X DELETE

问题是我不知道如何使用VBA中的-x。

我目前的其他调用的代码是

api_Key = getStripeAPI

req = "DELETE"

Set httpReq = CreateObject("MSXML2.ServerXMLHTTP")
httpReq.Open "POST", "https://api.stripe.com/v1/subscriptions/" & stripeSubID, False

httpReq.setRequestHeader "Authorization", "Bearer " & api_Key
httpReq.send req
strResponse = httpReq.responseText
Debug.Print strResponse
writeToText strResponse
Set parsed = JsonConverter.ParseJson(strResponse)

我知道上面的代码不正确 但如果有人能让我知道如何利用-X 那就太好了

vba ms-access curl
2个回答
2
投票

你已经在使用了,只是传错了参数。它的第一个参数是 .Open:

httpReq.Open "DELETE", "https://api.stripe.com/v1/subscriptions/" & stripeSubID, False

1
投票

OK wow I just figured it by myself... after 45 mins of trying.

对于那些正在寻找这个的人。

-x DELETE意味着使用DELETE作为 "GET""POST "选项。

工作代码:-x DELETE是指使用DELETE作为 "GET""POST "选项。

api_Key = getStripeAPI



Set httpReq = CreateObject("MSXML2.ServerXMLHTTP")
httpReq.Open "DELETE", "https://api.stripe.com/v1/subscriptions/" & stripeSubID, False

httpReq.setRequestHeader "Authorization", "Bearer " & api_Key
httpReq.send
strResponse = httpReq.responseText
Debug.Print strResponse
writeToText strResponse
Set parsed = JsonConverter.ParseJson(strResponse)
© www.soinside.com 2019 - 2024. All rights reserved.