【问题标题】:ASP Classic parse data from curl POST -FASP Classic 解析来自 curl POST -F 的数据
【发布时间】:2018-10-17 07:40:32
【问题描述】:

我有以下指向我的服务的 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】:

    这是来自CURL documentation

    -F, --form

    (HTTP SMTP IMAP) 对于 HTTP 协议族,这让 curl 模拟一个用户按下提交按钮的填充表单。 这会导致 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
    %>
    

    解析 SafeArray 并不容易

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

    -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
    

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

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

    有用的链接

    【讨论】:

    • 那个 Request.BinaryRead 似乎把我带到了某个地方......我会让你知道我在做什么。 10 倍!
    • @GilAllen 警告,解析二进制 SafeArray 不适合经典 ASP 中胆小的人。您可以通过使用-d 而不是-F 来使用application/x-www-form-urlencoded 而不是multipart/form-data POST 数据来避免这种情况,这将允许您使用Request.Form 检索值。
    • 确实,但我并不总是发送方。无论如何,看来发件人已经改变了POST格式,现在可以正常工作了。
    猜你喜欢
    • 1970-01-01
    • 2016-02-07
    • 2018-07-23
    • 2011-10-13
    • 2016-09-24
    • 1970-01-01
    • 2017-02-14
    • 2011-10-23
    相关资源
    最近更新 更多