我将原始 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--
有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top