如何在 asp classic 中使用 cURL 发布数据? [英] How can I post data using cURL in asp classic?

查看:39
本文介绍了如何在 asp classic 中使用 cURL 发布数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将数据从 order.asp 发布到 3rd 方 url?

How can I post data from order.asp to 3rd party url?

我有表单标签中的所有参数.

I have all parameters in form tag.

提交时,第 3 方希望我添加两个值作为标题.第三方代码如下

On submission 3rd party want me to add two values as header. 3rd party code is as below

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 吗?

I am using asp classic. Can I use response.AddHeader name,value to pass both values X-Api-Key and X-Auth-Token?

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

If not possible, then how to use curl in asp classic?

推荐答案

您可以使用 WinHttpRequest 对象

<%
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
%>

这只是一个硬编码的例子,通常你会通过某种方法构建data变量,而不是传递一个硬编码的字符串.

This is just a hard-coded example, usually you would build the data variable via some method rather then passing a hard-coded string.

Response.AddHeader() 在经典 ASP 中用于设置服务器发送响应时返回给客户端的 HTTP 标头.

Response.AddHeader() is used in Classic ASP to set HTTP headers being returned to the client when the server is sending a response.

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

In this scenario the ASP page is the client sending a request to another server so in this context you wouldn't use Response.AddHeader but the SetRequestHeader() method of the WinHttpRequest object instead.

这篇关于如何在 asp classic 中使用 cURL 发布数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆