Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Http 服务器端的多部分消息和POST参数_Http_Client Server_Multipart - Fatal编程技术网

Http 服务器端的多部分消息和POST参数

Http 服务器端的多部分消息和POST参数,http,client-server,multipart,Http,Client Server,Multipart,我试图在多部分消息中发布一个文件。问题是我需要为该文件传递两个额外的参数。我希望它们可以在POST参数数组中访问。问题是是否可以将部分添加到多部分消息中,以便将其解释为POST参数?还是我在浪费时间 我想要这个,例如: --1BEF0A57BE110FD467A\r\n Content-Disposition: form-data; name="name1"\r\n \r\n value\r\n 可通过$\u POST['name1'] PS:据我所知,如果使用actionscriptFile

我试图在多部分消息中发布一个文件。问题是我需要为该文件传递两个额外的参数。我希望它们可以在POST参数数组中访问。问题是是否可以将部分添加到多部分消息中,以便将其解释为POST参数?还是我在浪费时间

我想要这个,例如:

--1BEF0A57BE110FD467A\r\n
Content-Disposition: form-data; name="name1"\r\n
\r\n
value\r\n
可通过
$\u POST['name1']


PS:据我所知,如果使用actionscript
FileReference.upload(urlRequest)上传文件
并在
urlRequest
中指定post参数,然后它们将位于
$\u post

中。实际上,您想要做的正是多部分消息相对于
$\u post
数组的工作方式

考虑以下HTML表单:

<form action="/somefile.php" method="post" enctype="multipart/form-data">
  <input name="text1" type="text" />
  <input name="text2" type="text" />
  <input name="text3" type="text" />
  <input name="file" type="file" />
  <input type="submit" />
</form>
当我们在PHP中查看它时,如果我们
print\r($\u POST)我们应该得到如下内容:

POST /somefile.php HTTP/1.1
Host: somehost.com
Accept: */*
User-Agent: MyBrowser/1.0
Content-Type: multipart/form-data; boundary="this-is-a-boundary-string"

--this-is-a-boundary-string
Content-Dispostion: form-data; name="text1"

value1
--this-is-a-boundary-string
Content-Dispostion: form-data; name="text2"

value2
--this-is-a-boundary-string
Content-Dispostion: form-data; name="text3"

value3
--this-is-a-boundary-string
Content-Dispostion: form-data; name="file"; filename="file.txt"
Content-Type: text/plain

This is the contents of file.txt
--this-is-a-boundary-string--
Array
(
   [text1] => value1
   [text2] => value2
   [text3] => value3
)
…如果我们
print\r($\u文件)

…因此您可以看到,消息中
内容处置:
标题不包含
filename=”“
元素的部分被添加到
$\u POST
数组中,具有一个元素的部分被视为文件上载并添加到
$\u文件中


在构建要发送到服务器的
多部分/表单数据
消息时,我发现最简单的方法是构建您在请求中模仿的HTML表单,并根据HTML表单的行为构造HTTP消息。

实际上,您想要做的正是与
$\u POST
数组相关的多部分消息的工作方式

考虑以下HTML表单:

<form action="/somefile.php" method="post" enctype="multipart/form-data">
  <input name="text1" type="text" />
  <input name="text2" type="text" />
  <input name="text3" type="text" />
  <input name="file" type="file" />
  <input type="submit" />
</form>
当我们在PHP中查看它时,如果我们
print\r($\u POST)我们应该得到如下内容:

POST /somefile.php HTTP/1.1
Host: somehost.com
Accept: */*
User-Agent: MyBrowser/1.0
Content-Type: multipart/form-data; boundary="this-is-a-boundary-string"

--this-is-a-boundary-string
Content-Dispostion: form-data; name="text1"

value1
--this-is-a-boundary-string
Content-Dispostion: form-data; name="text2"

value2
--this-is-a-boundary-string
Content-Dispostion: form-data; name="text3"

value3
--this-is-a-boundary-string
Content-Dispostion: form-data; name="file"; filename="file.txt"
Content-Type: text/plain

This is the contents of file.txt
--this-is-a-boundary-string--
Array
(
   [text1] => value1
   [text2] => value2
   [text3] => value3
)
…如果我们
print\r($\u文件)

…因此您可以看到,消息中
内容处置:
标题不包含
filename=”“
元素的部分被添加到
$\u POST
数组中,具有一个元素的部分被视为文件上载并添加到
$\u文件中

在构建要发送到服务器的
多部分/表单数据
消息时,我发现最简单的方法是构建与请求相似的HTML表单,并根据HTML表单的行为构造HTTP消息