Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send and handle Http Post in asp?

Tags:

asp-classic

httpRequest.Open "POST", "www.example.com/handle.asp", False
httpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
httpRequest.send data
postResponse = httpRequest.response

How do i handle the post of the above code. in handle.asp. In handle i want to take the data being sent and add to it and then send something back to the calling page?

like image 495
Beginner Avatar asked Mar 14 '11 15:03

Beginner


People also ask

How do you write a post method?

To send data using the HTTP POST method, you must include the data in the body of the HTTP POST message and specify the MIME type of the data with a Content-Type header. Below is an example of an HTTP POST request to send JSON data to the server. The size and data type for HTTP POST requests is not limited.

What is the post method?

The POST Method POST is used to send data to a server to create/update a resource. Some notes on POST requests: POST requests are never cached. POST requests do not remain in the browser history.

Can I use POST method to retrieve data?

Yes, you can make it work at least using WCF, it's bit different in MVC and Web API where you add attributes to methods like [GET] [POST] etc..


1 Answers

@Uzi: Here's an example --

somefile.asp calling handle.asp which is the processing script:

Option Explicit

Dim data, httpRequest, postResponse

data = "var1=somevalue"
data = data & "&var2=someothervalue"
data = data & "&var3=someothervalue"

Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")
httpRequest.Open "POST", "http://www.example.com/handle.asp", False
httpRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
httpRequest.Send data

postResponse = httpRequest.ResponseText

Response.Write postResponse ' or do something else with it

Example of handle.asp:

Option Explicit

Dim var1, var2, var3

var1 = Request.Form("var1")
var2 = Request.Form("var2")
var3 = Request.Form("var3")

' Silly example of a condition / test '
If var1 = "somecondition" Then
    var1 = var1 & " - extra text"
End If

' .. More processing of the other variables .. '

' Processing / validation done... '
Response.Write var1 & vbCrLf
Response.Write var2 & vbCrLf
Response.Write var3 & vbCrLf
like image 183
stealthyninja Avatar answered Oct 10 '22 00:10

stealthyninja