Access to request body using classic ASP?

How do I access what was posted by the client on my classic ASP server? I know that there is a Request.Forms variable, but the client request was not created using the form. The client request body is just a string created using the standard POST operator. Thanks

+5
source share
3 answers

You need to read request bytes if the request content type sent by the client is not form data. In this case, the request is not form data accessible through name-value pairs, so you cannot use the Request.Form collection. I suggest exploring the BinaryRead method .

Reading posted data and converting to a string:

If Request.TotalBytes > 0 Then
    Dim lngBytesCount
        lngBytesCount = Request.TotalBytes
    Response.Write BytesToStr(Request.BinaryRead(lngBytesCount))
End If

Function BytesToStr(bytes)
    Dim Stream
    Set Stream = Server.CreateObject("Adodb.Stream")
        Stream.Type = 1 'adTypeBinary
        Stream.Open
        Stream.Write bytes
        Stream.Position = 0
        Stream.Type = 2 'adTypeText
        Stream.Charset = "iso-8859-1"
        BytesToStr = Stream.ReadText
        Stream.Close
    Set Stream = Nothing
End Function

Hope this helps.

Update # 1:

Using JScript

if(Request.TotalBytes > 0){
    var lngBytesCount = Request.TotalBytes
    Response.Write(BytesToStr(Request.BinaryRead(lngBytesCount)))
}

function BytesToStr(bytes){
    var stream = Server.CreateObject("Adodb.Stream")
        stream.type = 1
        stream.open
        stream.write(bytes)
        stream.position = 0
        stream.type = 2
        stream.charset = "iso-8859-1"
    var sOut = stream.readtext()
        stream.close
    return sOut
}
+18
source

In classic ASP, Request.Formthis is the collection used for any data sent through POST.

For completeness, I will add that Request.QueryStringis a collection used for any data sent via a GET / Query String.

, , -, Request.Form.


: , (, ), . , .


, , - - :

Response.Write(Request.Form)

- -

field=value&field2=value2

- , .

- , , , , .

0

To get the JSON string value, just use CStr(Request.Form)

It works with pleasure.

0
source