ASP Post data to URL

ASP Best Practices

ASP function to post form data to a URL and return the content.

Date : 2006-04-05
The first time I needed this function it was for posting data to for payment processing but there are many uses. The only caveat is the data sent must be formatted correctly. I've given a simple example of how it's used also.

Here it is:
Function PostTo(Data, URL)
  Dim objXMLHTTP, xml
  On Error Resume Next
  Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
  xml.Open "POST", URL, False
  xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  xml.Send Data
  If xml.readyState <> 4 then
    xml.waitForResponse 10
  End If
  If Err.Number = 0  AND http.Status = 200 then
    PostTo = xml.responseText
    PostTo = "Failed"
  End If
  Set xml = Nothing
End Function

PostData = "encoding=UTF-8&firstname=" & firstname & "&lastname=" & lastname & "&email=" & email & ""
rslt = PostTo(PostData,"")

Comments :

No comments yet
  • Search For Articles