用于模拟具有多值字段的表单的 Http 请求

发布于 2024-12-24 20:09:51 字数 1206 浏览 2 评论 0原文

我一直在使用这样的表单:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文