如何在 asp 经典中使用 cURL post 数据?

How can I post data using cURL in asp classic?

我怎样才能 post 从 order.asp 到第 3 方 url 的数据?

我在表单标签中有所有参数。

提交时,第 3 方要我添加两个值 header。第 3 方代码如下

curl https://www.instamojo.com/api/1.1/payment-requests/ \
  --header "X-Api-Key: [API_KEY]" \
  --header "X-Auth-Token: [AUTH_TOKEN]" \
  --data     
 "allow_repeated_payments=False&amount=2500&buyer_name=John+Doe&purpose=FIFA+16&redirect_url=http%3A%2F%2Fwww.example.com%2Fredirect%2F&phone=9999999999&send_email=True&webhook=http%3A%2F%2Fwww.example.com%2Fwebhook%2F&send_sms=True&email=foo%40example.com"

我正在使用 asp 经典版。我可以使用 response.AddHeader name,value 传递值 X-Api-KeyX-Auth-Token 吗?

如果不行,那么在asp classic中如何使用curl?

您可以使用 WinHttpRequest object

<%
Dim http: Set http = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
Dim url: url = "https://www.instamojo.com/api/1.1/payment-requests/"
Dim data: data = "allow_repeated_payments=False&amount=2500&buyer_name=John+Doe&purpose=FIFA+16&redirect_url=http%3A%2F%2Fwww.example.com%2Fredirect%2F&phone=9999999999&send_email=True&webhook=http%3A%2F%2Fwww.example.com%2Fwebhook%2F&send_sms=True&email=foo%40example.com"

With http
  Call .Open("POST", url, False)
  Call .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
  Call .SetRequestHeader("X-Api-Key", "yourvalue")
  Call .SetRequestHeader("X-Auth-Token", "yourvalue")
  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
%>

这只是一个 hard-coded 示例,通常您会通过某种方法构建 data 变量,而不是传递 hard-coded 字符串。

Response.AddHeader()呢?

Response.AddHeader() 在 Classic ASP 中用于设置 HTTP headers 在服务器发送响应时返回给客户端。

在这种情况下,ASP 页面是客户端向另一台服务器发送请求,因此在这种情况下,您不会使用 Response.AddHeader,而是 SetRequestHeader() 方法 WinHttpRequest object 代替。