curl - 如何在 asp classic 中使用 cURL 发布数据?

标签 curl vbscript asp-classic

我如何发布来自 order.asp 的数据到第 3 方网址?

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

提交时,第 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 执行此操作目的

<%
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变量通过某种方法而不是传递一个硬编码的字符串。
怎么样Response.AddHeader() ?Response.AddHeader()用于在经典 ASP 中设置服务器发送响应时返回给客户端的 HTTP header 。
在这种情况下,ASP 页面是客户端向另一台服务器发送请求,因此在这种情况下您不会使用 Response.AddHeaderSetRequestHeader() WinHttpRequest的方法对象。

关于curl - 如何在 asp classic 中使用 cURL 发布数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37462580/

相关文章:

php - Composer curl 错误 60 : SSL certificate problem: self signed certificate in certificate chain

php - 并行执行多个 php 脚本

php - 如何在 SOAP 请求的curl header 中添加ConfigurationName

javascript - 按钮 : calling "onclick" parent's element instead of itself (HTML Button) 的奇怪行为

batch-file - 如何在 Windows 中使用脚本运行多个快捷方式(.lnk 文件)?

cookies - 如何检索 ASP cookie 的 'Expires' 属性值?

sql-server - 使用经典 ASP 将文件上传到 SQL 数据库

php - 使用函数/对象和数据库时的最佳实践-一般问题

javascript - 有条件地在新选项卡中打开网址

php - Paypal setExpressCheckout nvp税额错误