使用经典ASP的cURL

euoag5mw  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(176)

我试图让SyncCentric与一个传统的经典ASP网站,目前正在使用Amzpecty。
如有任何帮助,将不胜感激!谢啦,谢啦
cURL请求应该是:

curl "https://app.synccentric.com/api/v3/products" \
  -H "Authorization: Bearer your-api-token" \
  -d "identifiers[0][identifier]=B00YECW5VM" \
  -d "identifiers[0][type]=asin" \
  -d "identifiers[1][identifier]=B00USV83JQ" \
  -d "identifiers[1][type]=asin" \
  -XPOST

字符串
下面是我将要使用的ASP代码,但我不知道如何将cURL请求转换为数据字符串:

Dim http: Set http = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
Dim url: url = "https://app.synccentric.com/api/v3/products"
Dim data: data = ""

With http
  Call .Open("POST", url, False)
  Call .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
  Call .SetRequestHeader("Authorization", "My API key")
  Call .Send(data)
End With

If Left(http.Status, 1) = 2 Then
  'Request succeeded with a HTTP 2xx response, do something...
Else
  'Output error
  Call Response.Write("Server returned: " & http.Status & " " & http.StatusText)
End If

ndasle7k

ndasle7k1#

线索在CURL手册页的-d, --data <data>部分下:
如果在同一命令行中多次使用这些选项中的任何一个,则指定的数据片段将用&-符号分隔。因此,使用'-d name=丹尼尔-d skill=lousy'将生成一个类似于'name=daniel&skill= lousy'的post块。
因此,您需要指定key=value,并使用与号分隔,就像使用原始HTTPPOST一样。

Dim http: Set http = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
Dim url: url = "https://app.synccentric.com/api/v3/products"
Dim data: data = "identifiers[0][identifier]=B00YECW5VM&identifiers[0][type]=asin&identifiers[1][identifier]=B00USV83JQ&identifiers[1][type]=asin"

With http
  Call .Open("POST", url, False)
  Call .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
  Call .SetRequestHeader("Authorization", "Bearer your-api-token")
  Call .Send(data)
End With

If Left(http.Status, 1) = 2 Then
  'Request succeeded with a HTTP 2xx response, do something...
Else
  'Output error
  Call Response.Write("Server returned: " & http.Status & " " & http.StatusText)
End If

字符串

有用链接

相关问题