How to perform an HTTP POST request in ASP?

You can try something like this:

Set ServerXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
ServerXmlHttp.open "POST", "http://www.example.com/page.asp"
ServerXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
ServerXmlHttp.setRequestHeader "Content-Length", Len(PostData)
ServerXmlHttp.send PostData

If ServerXmlHttp.status = 200 Then
    TextResponse = ServerXmlHttp.responseText
    XMLResponse = ServerXmlHttp.responseXML
    StreamResponse = ServerXmlHttp.responseStream
Else
    ' Handle missing response or other errors here
End If

Set ServerXmlHttp = Nothing

where PostData is the data you want to post (eg name-value pairs, XML document or whatever).

You’ll need to set the correct version of MSXML2.ServerXMLHTTP to match what you have installed.

The open method takes five arguments, of which only the first two are required:

ServerXmlHttp.open Method, URL, Async, User, Password
  • Method: “GET” or “POST”
  • URL: the URL you want to post to
  • Async: the default is False (the call doesn’t return immediately) – set to True for an asynchronous call
  • User: the user name required for authentication
  • Password: the password required for authentication

When the call returns, the status property holds the HTTP status. A value of 200 means OK – 404 means not found, 500 means server error etc. (See http://en.wikipedia.org/wiki/List_of_HTTP_status_codes for other values.)

You can get the response as text (responseText property), XML (responseXML property) or a stream (responseStream property).

Leave a Comment