bug^君 2010-12-24 12:19 采纳率: 25%
浏览 272
已采纳

Enctype"多部分 / 形式-数据"是什么意思?

What does enctype='multipart/form-data' mean in an HTML form and when should we use it?

转载于:https://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean

  • 写回答

7条回答 默认 最新

  • 衫裤跑路 2010-12-24 12:21
    关注

    When you make a POST request, you have to encode the data that forms the body of the request in some way.

    HTML forms provide three methods of encoding.

    • application/x-www-form-urlencoded (the default)
    • multipart/form-data
    • text/plain

    Work was being done on adding application/json, but that has been abandoned.

    The specifics of the formats don't matter to most developers. The important points are:

    When you are writing client-side code, all you need to know is use multipart/form-data when your form includes any <input type="file"> elements.

    When you are writing server-side code: Use a prewritten form handling library (e.g. Perl's CGI->param or the one exposed by PHP's $_POST superglobal) and it will take care of the differences for you. Don't bother trying to parse the raw input received by the server.

    Never use text/plain.


    If you are writing (or debugging) a library for parsing or generating the raw data, then you need to start worrying about the format. You might also want to know about it for interest's sake.

    application/x-www-form-urlencoded is more or less the same as a query string on the end of the URL.

    multipart/form-data is significantly more complicated but it allows entire files to be included in the data. An example of the result can be found in the HTML 4 specification.

    text/plain is introduced by HTML 5 and is useful only for debugging — from the spec: They are not reliably interpretable by computer — and I'd argue that the others combined with tools (like the Net tab in the developer tools of most browsers) are better for that).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况