ASP Classic解析来自curl POST -F的数据

问题描述 投票:1回答:1

我有以下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”)'。

你有什么主意吗?

vbscript asp-classic
1个回答
2
投票

这是来自CURL documentation

-F, - 表格

(HTTP SMTP IMAP)对于HTTP协议族,这使curl模拟用户按下提交按钮的填写表单。根据RFC 2388,这会导致使用Content-Type multipart / form-data卷曲数据。

当使用内容类型multipart/form-data将表单提交给Classic ASP时,唯一可用的方法是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
%>

Parsing a SafeArray isn't easy

如果你仍想使用Request.Form,可以使用-d而不是-F在CURL命令中指定表单参数。来自the documentation;

-d, - data

(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

然后,您将使用以下方法检索Classic ASP中的xx参数;

<%
Dim xx: xx = Request.Form("xx")
%>

Useful Links

© www.soinside.com 2019 - 2024. All rights reserved.