我如何用POST的multipart / form-data编码阵列? [英] How do I POST an array with multipart/form-data encoding?
问题描述
在一个GET参数字符串或X-WWW的形式urlen codeDPOST请求时,它可以通过用方括号它们命名(例如名称[])。<指定的参数数组/ p>
有没有一种正确(或至少广泛-S $ P $垫约定)的方式与一个的multipart / form-data的POST请求指定的参数数组?
请问下是正确的?
内容类型:多重/ form-data的;边界= - ABC--abc
内容处置:表格数据; NAME =名称[]第一个索引
--abc
内容处置:表格数据; NAME =名称[]第二个索引
如果它因平台而异,我感兴趣的公约的Apache / PHP。
如果你想要一个与之关联的数组您可以在表单域的名称传递指数:
内容类型:多重/ form-data的;边界= - ABC--abc
内容处置:表格数据; NAME =名称[首页]第一个值
--abc
内容处置:表格数据; NAME =名称[秒]第二个值
然后在PHP级别的print_r($ _ POST)会给你
阵列([名称] =>阵列([首页] =>第一个值[秒] =>第二个值))
块引用>如果你只是一个正常有序排列后,然后像你一样一样的:
内容类型:多重/ form-data的;边界= - ABC--abc
内容处置:表格数据; NAME =名称[]第一个索引
--abc
内容处置:表格数据; NAME =名称[]第二个索引然后在PHP级别的print_r($ _ POST)会给你
阵列([名称] =>阵列([0] =>第一个索引的 1 =>第二个索引))
块引用>PARAMS用[]在他们的名字翻译成阵列的服务器端是特定于PHP的功能(的 http://www.php.net/manual/en/faq.html.php#faq.html.arrays )。
对于多部分编码,你可以找到更多在RFC: http://www.ietf.org /rfc/rfc1867.txt
In a GET parameter string, or an "x-www-form-urlencoded" POST request, it's possible to specify an array of parameters by naming them with brackets (e.g. "name[]").
Is there a "correct" (or at least a wide-spread convention) way to specify an array of parameters with a "multipart/form-data" POST request?
Would the following be correct?
Content-Type: multipart/form-data; boundary=--abc --abc Content-Disposition: form-data; name="name[]" first index --abc Content-Disposition: form-data; name="name[]" second index
If it varies by platform, I'm interested in the convention for Apache/PHP.
解决方案If you want an associated array you can pass index in a name of a form field:
Content-Type: multipart/form-data; boundary=--abc --abc Content-Disposition: form-data; name="name[first]" first value --abc Content-Disposition: form-data; name="name[second]" second value
Then on php level print_r($_POST) would give you
Array ( [name] => Array ( [first] => first value [second] => second value ) )
If you are after just a normal ordered array then same as you did:
Content-Type: multipart/form-data; boundary=--abc --abc Content-Disposition: form-data; name="name[]" first index --abc Content-Disposition: form-data; name="name[]" second index
Then on php level print_r($_POST) would give you
Array ( [name] => Array ( [0] => first index 1 => second index ) )
Params with [] in their names translating into arrays on a server side is a feature specific to PHP (http://www.php.net/manual/en/faq.html.php#faq.html.arrays).
As for multipart encoding you can find more in RFC: http://www.ietf.org/rfc/rfc1867.txt
这篇关于我如何用POST的multipart / form-data编码阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!