使用什么 HTTP 标头来设置表单字段名称(multipart/form-data)

发布于 2024-07-05 05:24:06 字数 696 浏览 6 评论 0原文

我将原始 HTTP 请求传递到 apache 服务器(由 PHP 接收)。 该请求的类型为 multipart/form-data,即与提交 HTML 表单时使用的 MIME 类型相同。 但是,我不确定使用什么 HTTP 标头来设置表单字段名称(我只是假设它是定义此名称的标头,不知道它还可能是什么),然后可以在 PHP 中使用它来访问$_GET 或 $_FILES 中的字段。

HTTP 请求可能如下所示:

Content-type: multipart/form-data;boundary=main_boundary

--main_boundary
Content-type: text/xml
<?xml version='1.0'?>
<content>
Some content goes here
</content>

--main_boundary
Content-type: multipart/mixed;boundary=sub_boundary

  --sub_boundary
  Content-type: application/octet-stream

  File A contents

  --sub_boundary
  Content-type: application/octet-stream

  File B contents

  --sub_boundary

--main_boundary--

I'm passing raw HTTP requests to an apache server (received by PHP). The request is of type multipart/form-data, i.e. the same MIME type used when submitting HTML forms.
However, I'm not sure what HTTP header to use for setting the form field name (I'm just assuming it's a header defining this, don't know what else it could be) which then can be used in PHP to access the field in $_GET or $_FILES.

The HTTP request might look something like this:

Content-type: multipart/form-data;boundary=main_boundary

--main_boundary
Content-type: text/xml
<?xml version='1.0'?>
<content>
Some content goes here
</content>

--main_boundary
Content-type: multipart/mixed;boundary=sub_boundary

  --sub_boundary
  Content-type: application/octet-stream

  File A contents

  --sub_boundary
  Content-type: application/octet-stream

  File B contents

  --sub_boundary

--main_boundary--

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雾里花 2024-07-12 05:24:06

Content-Disposition 标头有一个包含控件名称的名称参数。 每个后面应该有一个 --sub_boundary

--sub_boundary
Content-Disposition: form-data; name="mycontrol"

我差点忘了:如果该字段是文件控件,则还有一个文件名字段和一个 Content-Type 标头

--sub_boundary
Content-Disposition: form-data; name="mycontrol"; filename="file1.xml"
Content-Type: application/xml;

,如果文件不是文本,则还需要

Content-Transfer-Encoding: binary

The Content-Disposition header has a name argument that has the control name. There should be one after each --sub_boundary

--sub_boundary
Content-Disposition: form-data; name="mycontrol"

I almost forgot: If the field is a file control, there's also a filename field and a Content-Type header

--sub_boundary
Content-Disposition: form-data; name="mycontrol"; filename="file1.xml"
Content-Type: application/xml;

and if the file is not text, you also need

Content-Transfer-Encoding: binary
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文