【问题标题】:Perl CGI says request is Bad (malformed multipart POST)Perl CGI 说请求是错误的(格式错误的多部分 POST)
【发布时间】:2018-12-04 11:41:16
【问题描述】:

我将以下请求从 Android java 代理发送到 Apache/2.4.6 CGI perl 脚本(Linux SUSE 13.1 上的 CGI.pm 4.38 / Perl 5.18.1)。转储 $cgi 显示如下:

[Mon Jun 25 12:22:52.025910 2018] [cgi:error] [pid 20515] [client 192.168.0.10:56197] AH01215: $VAR1 = bless( {
[Mon Jun 25 12:22:52.025963 2018] [cgi:error] [pid 20515] [client 192.168.0.10:56197] AH01215:                  'escape' => 1,
[Mon Jun 25 12:22:52.025977 2018] [cgi:error] [pid 20515] [client 192.168.0.10:56197] AH01215:                  '.fieldnames' => {},
[Mon Jun 25 12:22:52.026006 2018] [cgi:error] [pid 20515] [client 192.168.0.10:56197] AH01215:                  '.charset' => 'ISO-8859-1',
[Mon Jun 25 12:22:52.026019 2018] [cgi:error] [pid 20515] [client 192.168.0.10:56197] AH01215:                  'use_tempfile' => 1,
[Mon Jun 25 12:22:52.026031 2018] [cgi:error] [pid 20515] [client 192.168.0.10:56197] AH01215:                  'param' => {},
[Mon Jun 25 12:22:52.026044 2018] [cgi:error] [pid 20515] [client 192.168.0.10:56197] AH01215:                  '.parameters' => [],
[Mon Jun 25 12:22:52.026066 2018] [cgi:error] [pid 20515] [client 192.168.0.10:56197] AH01215:                  '.cgi_error' => '400 Bad request (malformed multipart POST)'
[Mon Jun 25 12:22:52.026076 2018] [cgi:error] [pid 20515] [client 192.168.0.10:56197] AH01215:                }, 'CGI' );

当我使用 ncat 捕获请求时,我看到以下内容,但不明白哪个部分不好(请注意 ^M 会自动添加到标头中)。任何帮助表示赞赏。

POST /cgi-bin/voicerec.cgi HTTP/1.1^M
Accept-Charset: UTF-8^M
Content-Type: multipart/form-data; boundary=-----OMT-164386aa112^M
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.2.2; GT-P5113 Build/JDQ39)^M
Host: 192.168.0.12:55000^M
Connection: Keep-Alive^M
Accept-Encoding: gzip^M
Content-Length: 515^M
^M


-------OMT-164386aa112
Content-Disposition: form-data; name="action"

as_voice_rec
-------OMT-164386aa112
Content-Disposition: form-data; name="S_UID"

a
-------OMT-164386aa112
Content-Disposition: form-data; name="voice"; filename="audiorecrodtest.3gp"
Content-Type: application/x-object
Here goes the voice data file content.-------OMT-164386aa112--

【问题讨论】:

  • 我正在将我的请求数据与W3.org 上的规范进行比较,并且没有发现我的请求格式有任何明显的问题。

标签: perl http post cgi


【解决方案1】:
-------OMT-164386aa112
Content-Disposition: form-data; name="voice"; filename="audiorecrodtest.3gp"
Content-Type: application/x-object
Here goes the voice data file content.-------OMT-164386aa112--

这部分有很多问题:没有标题结束标记,即标题和正文之间没有空行。并且 MIME 边界-------OMT-164386aa112-- 必须从行首开始。

【讨论】:

  • 感谢您的回复。最后一个边界现在是一个新的行,但没有任何区别。什么是“标题结尾”标记?你能详细说明一下吗?
  • @BReddy: " 什么是"end-of-header" 标记?" - 引用我自己的话:"没有 end-of-header 标记,即 标题和正文之间没有空行"
  • 再次感谢,我在另一篇文章中看到了该建议,并在标题之后和表单数据开始之前添加了 2 个空行。它显示在我发布的请求中。我错过了什么吗?
  • @BReddy:再次引用我自己的话:"...this 部分有很多问题..."。我实际上已经引用了相关的 MIME 部分。更清楚地说:如果这部分,即在“Here go...”之前,则在正文之前应该有一个空行。我真的建议使用一些 MIME 库,或者先学习并实施相关标准,而不是猜测这可能如何工作。
猜你喜欢
  • 1970-01-01
  • 2016-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-14
  • 1970-01-01
  • 1970-01-01
  • 2022-01-04
相关资源
最近更新 更多