HTTP 多部分 (POST) 请求中的边界参数是什么?
我正在尝试开发一个侧边栏小工具,该小工具可以自动检查网页以了解传输配额的变化。我快要完成了,但我还需要最后一步才能使其正常工作:将带有正确 POST 数据的 HttpRequest 发送到 php 页面。使用firefox插件,标题的“Content-Type”如下所示:
Content-Type=multipart/form-data; boundary=---------------------------99614912995
参数“boundary”似乎是随机的,POSTDATA是这样的:
POSTDATA =-----------------------------99614912995
Content-Disposition: form-data; name="SOMENAME"
Formulaire de Quota
-----------------------------99614912995
Content-Disposition: form-data; name="OTHERNAME"
SOMEDATA
-----------------------------99614912995--
我不明白如何正确模拟带有神秘的POSTDATA “边界”参数回来了。
有人知道我该如何解决这个问题吗?
I am trying to develop a sidebar gadget that automates the process of checking a web page for the evolution of my transfer quota. I am almost at it but there is one last step I need to get it working: Sending an HttpRequest with the correct POST data to a php page. Using a firefox plugin, here is what the "Content-Type" of the header looks like:
Content-Type=multipart/form-data; boundary=---------------------------99614912995
with the parameter "boundary" seeming to be random, and the POSTDATA is this:
POSTDATA =-----------------------------99614912995
Content-Disposition: form-data; name="SOMENAME"
Formulaire de Quota
-----------------------------99614912995
Content-Disposition: form-data; name="OTHERNAME"
SOMEDATA
-----------------------------99614912995--
I do not understand how to correctly emulate the POSTDATA with the mystery "boundary" parameter coming back.
Would someone know how I can solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
引用 RFC 1341,第 7.2.1 节,我认为是
Content-Type
标头的boundary
参数上的相关位(对于 MIME):然后澄清:
注意事项:
最后但并非最不重要的:
我希望这对将来的其他人有帮助,因为我必须漫游一段时间才能获得完整的图片(请确保阅读必要的 RFC 以获得最深入的理解)。
To quote from the RFC 1341, section 7.2.1, what I consider to be the relevant bits on the
boundary
parameter of theContent-Type
header (for MIME):and then clarifies:
Things to Note:
Last but not least:
I hope this helps someone else in the future, as I had to roam for a while before getting the full picture (please ensure to read the necessary RFCs to get the deepest understanding).
边界参数设置为多个连字符加上末尾的随机字符串,但您可以将其设置为任何值。问题是,如果边界字符串出现在请求数据中,它将被视为边界。
有关一些提示以及发送 multipart/form-data 的示例函数,请参阅我对 这个问题。修改该函数以对您想要发送的每个部分使用循环并不会太困难。
The boundary parameter is set to a number of hyphens plus a random string at the end, but you can set it to anything at all. The problem is, if the boundary string shows up in the request data, it will be treated as a boundary.
For some tips, and an example function for sending multipart/form-data see my answer to this question. It wouldn't be too difficult to modify that function to use a loop for each part you would like to send.
multipart/form-data 的实际规范位于 RFC 7578 中。边界在第 4.1 节中定义。
The actual specification for multipart/form-data is in RFC 7578. Boundary is defined in Section 4.1.