Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I POST data to a remote URL in Classic ASP?

Tags:

I need to POST data to a url in the middle of a script.

  1. User fills out form:
  2. Form submits to process.asp: I need to POST data to a 3rd Party integration at this point.
  3. process.asp finishes and directs user to thank you page.
like image 844
nrhammond Avatar asked Dec 19 '08 17:12

nrhammond


1 Answers

I'm not sure why everybody else is posting ASP.Net solutions when you specifically said you're using ASP "classic."

Something like this should work. I didn't write the code; I found it elsewhere. But the MSXML2.ServerXMLHTTP object is what you want to use if you don't want to purchase something commercial.

function getHTML (strUrl)     Set xmlHttp = Server.Createobject("MSXML2.ServerXMLHTTP")     xmlHttp.Open "GET", strUrl, False     xmlHttp.setRequestHeader "User-Agent", "asp httprequest"     xmlHttp.setRequestHeader "content-type", "application/x-www-form-urlencoded"     xmlHttp.Send     getHTML = xmlHttp.responseText     xmlHttp.abort()     set xmlHttp = Nothing    end function  

You might need to add some error-handling code to that for use in a production environment. I believe that object throws errors if it gets a 404 or timeout error. You'll need to "trap" them ASP-style (yuck) by setting On Error Resume Next before the .Send and then examine the ASP error object to see if there was a problem.

Good luck!

like image 150
John Rose Avatar answered Oct 03 '22 16:10

John Rose