Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I post data using cURL in asp classic?

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

I have all parameters in form tag.

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"

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

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

like image 524
lokesh purohit Avatar asked May 26 '16 13:05

lokesh purohit


1 Answers

You can do this using the 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
%>

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

What about Response.AddHeader()?

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

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.

like image 126
user692942 Avatar answered Oct 05 '22 20:10

user692942