Html 多部分/表单数据示例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4238809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Example of multipart/form-data
提问by user496949
I am wondering if anyone can share with me an example of multipart/form-data that contains:
我想知道是否有人可以与我分享包含以下内容的 multipart/form-data 示例:
- Some form parameters
- Multiple files
- 一些表单参数
- 多个文件
回答by pippo
Many thanks to @fxsc answer! I found that his choice for boundary is quite "unhappy" because all of thoose hyphens: in fact, as @Fake Name commented, when you are using your boundary inside request it comes with two more hyphens on front:
非常感谢@fxsc 的回答!我发现他对边界的选择非常“不高兴”,因为所有的连字符:事实上,正如@Fake Name 评论的那样,当你在请求中使用你的边界时,它前面还有两个连字符:
Example:
例子:
POST / HTTP/1.1
HOST: host.example.com
Cookie: some_cookies...
Connection: Keep-Alive
Content-Type: multipart/form-data; boundary=12345
--12345
Content-Disposition: form-data; name="sometext"
some text that you wrote in your html form ...
--12345
Content-Disposition: form-data; name="name_of_post_request" filename="filename.xyz"
content of filename.xyz that you upload in your form with input[type=file]
--12345
Content-Disposition: form-data; name="image" filename="picture_of_sunset.jpg"
content of picture_of_sunset.jpg ...
--12345--
I found on this w3.org pagethat is possible to incapsulate multipart/mixed header in a multipart/form-data, simply choosing another boundary string inside multipart/mixed and using that one to incapsulate data. At the end, you must "close" all boundary used in FILO order to close the POST request (like:
我在这个 w3.org 页面上发现可以将 multipart/mixed 头封装在 multipart/form-data 中,只需在 multipart/mixed 中选择另一个边界字符串并使用它来封装数据。最后,您必须“关闭” FILO 中使用的所有边界以关闭 POST 请求(例如:
POST / HTTP/1.1
...
Content-Type: multipart/form-data; boundary=12345
--12345
Content-Disposition: form-data; name="sometext"
some text sent via post...
--12345
Content-Disposition: form-data; name="files"
Content-Type: multipart/mixed; boundary=abcde
--abcde
Content-Disposition: file; file="picture.jpg"
content of jpg...
--abcde
Content-Disposition: file; file="test.py"
content of test.py file ....
--abcde--
--12345--
Take a look at the link above.
看看上面的链接。