asp-classic - 如何在 asp classic 中获取 request.body 值?
问题描述
在一个 .asp 经典页面中,我收到了一个 POST 发送给我(一个 JSON 字符串),它是在发送中发送的request.body
,这家伙说如何发送它。但如果我只是有theresponse=request.form
我什么都得不到?
那么我如何从 a 中获取值request.body
?
解决方案
我过去使用的一些支付网关 API 以这种方式发送响应。数据 (JSON) 作为二进制正文发送。
要阅读它,您需要使用Request.BinaryRead
with 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
推荐阅读
- android - 任务“:app:validateSigningRelease”执行失败
- javascript - 国际电话输入中的 jquery 验证错误后,国家/地区代码被附加到字段中
- symfony - 按查询计算分组结果
- javascript - 带退格键并删除
- google-apps-marketplace - 在 Google Marketplace 中发布部分启用的附加组件
- css - 为什么 Safari 浏览器中的边框会被切掉?
- javascript - 自定义登录按钮不保存登录状态
- swift - 如何将 uiviewcontroller 数据传递给 swiftui 小部件类
- python - PyTorch 在使用 docker 和 CPU 的不同机器上的结果非常不同
- python - 用于停止函数的python计时器