Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform an HTTP POST request in ASP?

How would I go about creating a HTTP request with POST data in classic asp (not .net) ?

like image 233
Christopher Tarquini Avatar asked Sep 23 '09 02:09

Christopher Tarquini


People also ask

What is post method in ASP?

The POST Method POST is used to send data to a server to create/update a resource. The data sent to the server with POST is stored in the request body of the HTTP request: POST /test/demo_form.php HTTP/1.1. Host: w3schools.com.

What is HTTP POST give an example?

HTTP works as a request-response protocol between a client and a server in a format that both HTTP clients and servers can understand. For example, when a user uploads a document to the server, the browser sends an HTTP POST request and includes the document in the body of the POST message.

What is HTTP POST form?

In computing, POST is a request method supported by HTTP used by the World Wide Web. By design, the POST request method requests that a web server accept the data enclosed in the body of the request message, most likely for storing it. It is often used when uploading a file or when submitting a completed web form.


1 Answers

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).

like image 174
Simon Forrest Avatar answered Oct 19 '22 15:10

Simon Forrest