10
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?

casperOne
  • 73,706
  • 19
  • 184
  • 253
Beginner
  • 28,539
  • 63
  • 155
  • 235

2 Answers2

25

@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
stealthyninja
  • 10,343
  • 11
  • 51
  • 59
  • 1
    This is great - I was looking for a way to manually craft an html form post by7 means of code in classic asp - which would simulate an actual form post. Thank you. I was struggling with the way one adds (Request.Form) parameters and values, this is exactly what I was looking for. Thank you. – Jonno Mar 31 '22 at 23:40
0

Exactly as you would handle the posted data usually in ASP by using Request.Form("parameter") to read out POSTed values and do whatever you want with them.

You just need to ensure to return the data from the handling script in a format easily decodable/usable by the script that makes the POST request.

RobV
  • 28,022
  • 11
  • 77
  • 119