http - HTTP 多部分 (POST) 请求中的边界参数是什么?

标签 http xmlhttprequest mime-types multipartform-data

我正在尝试开发一个侧边栏小工具,它可以自动执行检查网页以了解我的传输配额变化的过程。我快要完成了,但我还需要最后一步才能使其正常工作:将带有正确 POST 数据的 HttpRequest 发送到 php 页面。使用 firefox 插件,标题的“Content-Type”如下所示:

Content-Type=multipart/form-data; boundary=---------------------------99614912995

参数“边界”似乎是随机的,POSTDATA 是这样的:

POSTDATA =-----------------------------99614912995
Content-Disposition: form-data; name="SOMENAME"

Formulaire de Quota
-----------------------------99614912995
Content-Disposition: form-data; name="OTHERNAME"

SOMEDATA
-----------------------------99614912995--

我不明白如何使用返回的神秘“边界”参数正确模拟 POSTDATA。

有人知道我该如何解决这个问题吗?

最佳答案

引用自RFC 1341, section 7.2.1 ,我认为是 Content-Type header (对于 MIME)的 boundary 参数上的相关位:

All subtypes of "multipart" share a common syntax ...

The Content-Type field for multipart entities requires one parameter, "boundary", which is used to specify the encapsulation boundary. The encapsulation boundary is defined as a line consisting entirely of two hyphen characters ("-", decimal code 45) followed by the boundary parameter value from the Content-Type header field.

然后澄清:

Thus, a typical multipart Content-Type header field might look like this:

 Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08jU534c0p

This indicates that the entity consists of several parts, each itself with a structure that is syntactically identical to an RFC 822 message, except that the header area might be completely empty, and that the parts are each preceded by the line --gc0p4Jq0M2Yt08jU534c0p

注意事项:

  1. 封装边界必须出现在一行的开头,即在 CRLF(回车换行符)之后
  2. 边界必须紧跟另一个 CRLF 和下一部分的头字段,或者紧跟两个 CRLF,在这种情况下下一部分没有头字段(因此假定是 Content-输入文本/纯文本)。
  3. 封装边界不得出现在封装内,并且不得超过 70 个字符,不包括两个前导连字符。

最后但同样重要的是:

The encapsulation boundary following the last body part is a distinguished delimiter that indicates that no further body parts will follow. Such a delimiter is identical to the previous delimiters, with the addition of two more hyphens at the end of the line:

 --gc0p4Jq0M2Yt08jU534c0p-- 

我希望这对以后的其他人有所帮助,因为在了解全貌之前我不得不漫游了一段时间(请确保阅读必要的 RFC 以获得最深刻的理解)。

关于http - HTTP 多部分 (POST) 请求中的边界参数是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2305218/

相关文章:

internet-explorer - IE 和内容处置内联与扩展 token

java - 异步 HTTP 客户端加载了太多数据?

javascript - 访问node.js中xhr请求发送的数据

python - 假设我有一个 StringIO 文件。如何使用 python-magic 检查其文件类型?

asp.net-mvc - Asp.Net MVC2 RenderAction 更改页面 mime 类型?

java - 如何知道多部分请求中该部分的真实内容类型是什么

azure - 我们可以使用 OAuth 将数据放入 Azure 事件中心吗

http - Web 浏览器并行下载与流水线

javascript - ReactJS 获取 XMLHttpRequest 不工作

javascript - HTML表格-为每个<td>创建弹出框并显示xml数据