用于模拟具有多值字段的表单的 Http 请求
我一直在使用这样的表单:
<form method="POST" action="script.php" enctype="multipart/form-data">
<fieldset id="form-1">
<legend>Form-1</legend>
Some Field:
<input type="text" name="formsets[0][somefield]" />
Another Field:
<input type="text" name="formsets[0][anotherfield]" />
</fieldset>
<fieldset id="form-2">
<legend>Form-2</legend>
Some Text:
<textarea name="formsets[1][sometext]"></textarea>
<fieldset>
<legend>Upload Pictures:</legend>
<input type="file" name="formsets[1][pictures][0]" />
<input type="file" name="formsets[1][pictures][1]" />
</fieldset>
</fieldset>
<fieldset id="buttons">
<input type="submit" />
</fieldset>
</form>
然后在 PHP 中,我使用循环来处理 $_POST 和 $_FILES 数组中的传入数据。出于教育目的,我想知道将表单提交到服务器时生成的 http 请求是什么样的?
所以,我一直在使用 multpart/form-data 并且已经了解边界的东西,到目前为止我没有遇到任何问题,但是当涉及到发送具有多值字段的表单请求时,我无能为力。我被告知要使用“多部分/混合”和具有自己边界的嵌套块,但它对我不起作用。
那么,你能帮我构建 http 请求代码来实现这一点吗?
I have being working with forms like this:
<form method="POST" action="script.php" enctype="multipart/form-data">
<fieldset id="form-1">
<legend>Form-1</legend>
Some Field:
<input type="text" name="formsets[0][somefield]" />
Another Field:
<input type="text" name="formsets[0][anotherfield]" />
</fieldset>
<fieldset id="form-2">
<legend>Form-2</legend>
Some Text:
<textarea name="formsets[1][sometext]"></textarea>
<fieldset>
<legend>Upload Pictures:</legend>
<input type="file" name="formsets[1][pictures][0]" />
<input type="file" name="formsets[1][pictures][1]" />
</fieldset>
</fieldset>
<fieldset id="buttons">
<input type="submit" />
</fieldset>
</form>
In PHP I then use loops to process incoming data in $_POST and $_FILES arrays. For educational purposes I want to know what the resulting http request looks like when the form is submitted to the server?
So, I have been playing around with multpart/form-data and already know about the boundary stuff, this far I've had no problems, but when it comes to sending form requests that have multi-value fields I can't do much. I've been told to use the "multipart/mixed" and nesting chunks with their own boundaries but it didn't work for me.
So, do you help me build the http request code to achieve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论