如何在asp经典中获取request.body值?
How to get the request.body value in asp classic?
在 .asp 经典页面中,我收到一个 POST 发送给我(一个 JSON 字符串),它在 request.body
中发送,说那家伙怎么送的。
但是如果我只有 theresponse=request.form
我什么也得不到?
那么如何从 request.body
中获取值?
我过去使用的一些支付网关 API 以这种方式发送响应。数据 (JSON) 作为二进制体发送 post.
要阅读它,您需要使用 Request.BinaryRead
和 Request.TotalBytes
,然后使用 Adodb.Stream
将二进制文件转换为 UTF8 文本:
Response.ContentType = "application/json"
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 = "utf-8"
BytesToStr = Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
' You shouldn't really be receiving any posts more than a few KB,
' but it might be wise to include a limit (200KB in this example),
' Anything larger than that is a bit suspicious. If you're dealing
' with a payment gateway the usual protocol is to post the JSON
' back to them for verification before processing.
if Request.TotalBytes > 0 AND Request.TotalBytes <= 200000 then
Dim postBody
postBody = BytesToStr(Request.BinaryRead(Request.TotalBytes))
Response.Write(postBody) ' the JSON... hopefully
end if
在 .asp 经典页面中,我收到一个 POST 发送给我(一个 JSON 字符串),它在 request.body
中发送,说那家伙怎么送的。
但是如果我只有 theresponse=request.form
我什么也得不到?
那么如何从 request.body
中获取值?
我过去使用的一些支付网关 API 以这种方式发送响应。数据 (JSON) 作为二进制体发送 post.
要阅读它,您需要使用 Request.BinaryRead
和 Request.TotalBytes
,然后使用 Adodb.Stream
将二进制文件转换为 UTF8 文本:
Response.ContentType = "application/json"
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 = "utf-8"
BytesToStr = Stream.ReadText
Stream.Close
Set Stream = Nothing
End Function
' You shouldn't really be receiving any posts more than a few KB,
' but it might be wise to include a limit (200KB in this example),
' Anything larger than that is a bit suspicious. If you're dealing
' with a payment gateway the usual protocol is to post the JSON
' back to them for verification before processing.
if Request.TotalBytes > 0 AND Request.TotalBytes <= 200000 then
Dim postBody
postBody = BytesToStr(Request.BinaryRead(Request.TotalBytes))
Response.Write(postBody) ' the JSON... hopefully
end if