How to send and process Http Post in asp?

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 message of the above code. in handle.asp. In the descriptor, I want the data to be sent and added to it, and then sent something back to the calling page?

+6
asp-classic
source share
2 answers

@Uzi: Here's an example -

somefile.asp call 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 

handle.asp example:

 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 
+16
source

Just as you would handle published data, usually in ASP, using Request.Form("parameter") to read the POSTed values ​​and do whatever you want with them.

You just need to ensure that the data from the processing of the script is returned in a format that is easily decoded / used by the script that makes the POST request.

0
source

All Articles