vbscript - ASP Classic 解析来自 curl POST -F 的数据
问题描述
我有以下指向我的服务的 CURL 请求:
curl -X POST \
http://go.example.com/ \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Postman-Token: cf0c1ab5-08ff-1aa2-428e-24b855e1a61c' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F fff=vvvvv \
-F rrrr=ddddd \
-F xx=something
我试图在经典的 ASP 代码中捕捉 xx 参数。我试过'Request(“xx”)'和'Request.Form(“xx”)'。
你有什么主意吗?
解决方案
这是来自CURL 文档
-F,--表格
(HTTP SMTP IMAP)对于 HTTP 协议族,这让 curl 模拟用户按下提交按钮的填写表单。这会导致 curl根据 RFC 2388使用 Content-Type multipart/form-data发布数据。
当使用内容类型将表单提交给 Classic ASP 时multipart/form-data
,唯一可用的方法是Request.BinaryRead()
按原样Request.Form
处理application/x-www-form-urlencoded
数据。
Request.BinaryRead()
这是一个让您入门的快速示例:
<%
'Should be less than configured request limit in IIS.
Const maxRequestSizeLimit = ...
Dim dataSize: dataSize = Request.TotalBytes
Dim formData
If dataSize < maxRequestSizeLimit Then
'Read bytes into a SafeArray
formData = Request.BinaryRead(dataSize)
'Once you have a SafeArray its up to you to process it.
...
Else
Response.Status = "413 PAYLOAD TOO LARGE"
Response.End
End If
%>
解析 SafeArray 并不容易
如果您想继续使用Request.Form
,可以通过在 CURL 命令中使用-d
而不是指定表单参数来完成-F
。从文档中;
-d,--数据
(HTTP) 将 POST 请求中的指定数据发送到 HTTP 服务器,就像浏览器在用户填写 HTML 表单并按下提交按钮时所做的一样。这将导致 curl 使用 content-type application/x-www-form-urlencoded 将数据传递给服务器。与 -F、--form 进行比较。
所以 CURL 命令会是这样的;
curl -X POST \
http://go.mytest-service.com/ \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d fff=vvvvv \
-d rrrr=ddddd \
-d xx=something
然后,您将使用以下xx
方法在 Classic ASP 中检索参数;
<%
Dim xx: xx = Request.Form("xx")
%>
有用的链接
- 应用程序/x-www-form-urlencoded 还是 multipart/form-data?
- MSDN - Request.BinaryRead 方法
- 解析 SafeArray 的示例类 (特别是
BuildUpload()
采用 SafeArray 并解析二进制文件的方法) - 在 Planet Source Code 上使用 Request.BinaryRead() 实现 File Uploader 类的示例
推荐阅读
- java - 如何一次使用 openGL ES 渲染多纹理?
- elasticsearch - Logstash - 按关键字过滤系统日志
- java - 如何使用自定义ErrorController返回jsp?
- html - 使用 Tailwind CSS 的侧边栏中的下拉菜单
- qt - 如何在多个设备上同步 QAudioOutput?
- c# - 如何在 c# windows 窗体中的对象上放置阴影?
- python - 将两列值合并为一列,并在 DataFrame 中将其名称作为行值创建另一列
- typescript - 如何获取函数参数类型
- php - Laravel smlink 未找到
- shader - 如何将自定义片段着色器应用于 MapBox GL JS 上的光栅图块?