我如何发布来自 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-Key
和 X-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.AddHeader
但SetRequestHeader()
WinHttpRequest
的方法对象。
关于curl - 如何在 asp classic 中使用 cURL 发布数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37462580/