MIME (Multipurpose Internet Mail Extensions) 是描述内容类型的互联网标准。Clients use this content type or media type header to select an appropriate viewer application for the type of data the header indicates.  数据接收方根据MIME type of content进行不同的解析。

MIME 消息包含文本(text/…)、图像(image/…)、音频(audio/…)、视频(video/…)以及其他应用程序专用(application/…)的数据。type/subtype

<form> 标签的 enctype 属性指定发往服务器的数据的MIME类型。只有 method="post" 时才使用 enctype 属性。

取值

描述

application/x-www-form-urlencoded

在发送前会根据HTTP标准编码所有字符(k=v&k2=v2),空格转换为 "+" ,特殊符号转换为 ASCII HEX 值。【在url规范中空格要编码成%20】

multipart/form-data

不对字符编码,会增加MIME headers。use when forms contain files, non-ASCII data, and binary data.一般上传文件时需要指定该类型。

text/plain

空格转换为 "+" 加号,不对特殊字符编码。

fname字段的value='chen 1'和name字段的value='kevin 1'在不同MIME类型下的表现形式:

application/x-www-form-urlencoded(表单默认的content-type)

For application/x-www-form-urlencoded, the body of the HTTP message sent to the server is essentially one giant query string -- name/value pairs are separated by the ampersand (&), and names are separated from values by the equals symbol (=). An example of this would be:

  MyVariableOne=ValueOne&MyVariableTwo=ValueTwo

According to the specification:

[Reserved and] non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character

That means that for each non-alphanumeric byte that exists in one of our values, it's going to take three bytes to represent it. For large binary files, tripling the payload is going to be highly inefficient.

multipart/form-data

会将多个表单的数据处理为一条消息,数据块以分隔符------{boundary}开始,以 ------{boundary}--结束。还会有Content-Type属性说明文件类型,content-disposition属性说明字段的一些具体信息。

That's where multipart/form-data comes in. With this method of transmitting name/value pairs, each pair is represented as a "part" in a MIME message (). Parts are separated by a particular string boundary (chosen specifically so that this boundary string does not occur in any of the "value" payloads). Each part has its own set of MIME headers like Content-Type, and particularly Content-Disposition, which can give each part its "name." The value piece of each name/value pair is the payload of each part of the MIME message. The MIME spec gives us more options when representing the value payload -- we can choose a more efficient encoding of binary data to save bandwidth (e.g. base 64 or even raw binary).

Why not use multipart/form-data all the time? For short alphanumeric values (like most web forms), the overhead of adding all of the MIME headers is going to significantly outweigh any savings from more efficient binary encoding.

payload:数据在传输过程中会根据各种协议进行封装,以保证可靠性。去除这些包裹层后真正需要传输的数据即payload。 

不同的参数传递方式,服务端获取参数的方式也不同。  

对于提交的application/x-www-form-urlencoded数据(ajax或表单), 在servlet中可以通过request.getParameter(name)的形式来获取表单参数。

对于multipart/form-data类型的数据,后台一般需要通过获取原始数据流做特别处理。

使用原生Ajax Post请求且未指定content-type时,默认使用Content-Type:text/plain;charset=UTF-8头部,在chrome中请求参数会显示在Request Payload部分。后台接受数据后只能当作普通字符使用,不能使用常用API获取参数。

jQuery.ajax()中默认的content-type为application/x-www-form-urlencoded类型,浏览器会将数据编码成标准的query String,在chrome的Form Data部分可以看到对应的值。适合传键值对数据(’key=value’或{key:value}),不适合对象嵌套对象的数据

application/json

以json格式的字符串形式传递参数,在jQuery中需要用JSON.Stringfy()将对象字符串化。如果直接传对象,最外层的括号会被去掉,导致解析错误。大多数后端语言都支持解析json格式的数据。

 

query string parameters 请求url中的query部分,get和post请求都可以携带。

前台提交数据(表单数据、Json数据及上传文件)的类型的更多相关文章

  1. from表单实现无跳转上传文件,接收页面后台数据。

    本文基于我刚写的http://www.cnblogs.com/iwang5566/p/6287529.html进行了简单的扩展,实现页面无跳转表单数据提交,并接收后台返回的数据. 下载好,上一篇文章d ...

  2. from表单实现无跳转上传文件,接收页面后台数据

    实现无跳转发送表单数据.文件,并能接收后台返回的数据. 主要技术要点: 1.form表单添加target属性,指定一个iframme的name:form表单提交后在iframe内嵌窗口接受响应,主页面 ...

  3. 使用django表单,使网页添加上传文件,并分析文件。

    开发环境是: apache + python + django+ eclipse(开发环境) 欲达到目的: 在网页上,添加上传文件控件.然后读取csv文件,并分析csv文件. 操作步骤: django ...

  4. HTML5 FormData 模拟表单控件 支持异步上传二进制文件 移动端

    FormData是XMLHttpRequest Level 2添加的一个新的接口,利用FormData对象,我们可以通过JavaScript用一些键值对来模拟一系列表单控件,还可以使用XMLHttpR ...

  5. 摒弃FORM表单上传图片,异步批量上传照片

    之前作图像处理一直在用form表单做图片数据传输, 个人感觉low到爆炸而且用户体验极差,现在介绍一个一部批量上传图片的小技巧,忘帮助他人的同时也警醒自己在代码的编写时不要只顾着方便,也要考虑代码的健 ...

  6. form表单转换为Json数据

    最近对前端js学习有点多,如今想自己动手写点插件,后来发现,我想到的,其他人都想到了.于是做了以下笔记. 使用插件: 插件 :https://github.com/marioizquierdo/jqu ...

  7. Form key length limit 2048 exceeded ,提交数据时,数据的键过长 或者是上传文件过大

    在ASP.NET Core MVC中,文件的key 默认最大为2048,文件上传的最大上传文件默认为20MB,如果我们想上传一些比较大的文件,就不知道怎么去设置了,没有了Web.Config我们应该如 ...

  8. jQuery Ajax使用FormData上传文件和其他数据,后端web.py获取

    参考博文: 通过jQuery Ajax使用FormData对象上传文件 方法一:使用<form>表单初始化FormData对象方式上传文件 前端(JQuery): <form enc ...

  9. c# 模拟表单提交,post form 上传文件、大数据内容

    表单提交协议规定:要先将 HTTP 要求的 Content-Type 设为 multipart/form-data,而且要设定一个 boundary 参数,这个参数是由应用程序自行产生,它会用来识别每 ...

  10. c# 模拟表单提交,post form 上传文件、数据内容

    转自:https://www.cnblogs.com/DoNetCShap/p/10696277.html 表单提交协议规定:要先将 HTTP 要求的 Content-Type 设为 multipar ...

随机推荐

  1. QT for Android记录

    1.<Qt on Android核心编程> blog: http://blog.csdn.net/foruok/article/details/38510195

  2. 【wireshark】插件开发(二):Lua插件开发介绍

    1. Wireshark对Lua的支持 本节相关内容可参考Wireshark开发指南第10章”Lua Support in Wireshark”. Wireshark集成了Lua解释器,以支持Lua脚 ...

  3. 使用git时出现Please make sure you have the correct access rights and the repository exists.问题已解决。

    使用git时,出现Please make sure you have the correct access rights and the repository exists.问题已解决. 今天我在使用 ...

  4. “context:include-filter”与“context:exclude-filter”标签作用解释

    注意到spring中<context:component-scan>标签中会出现include和exclude的子标签,具体是做什么用的? spring的配置文件与springmvc的配置 ...

  5. GDAL VS2010 win7(64位)安装、使用说明(图文解析)

    一.电脑配置及安装版本 Win 7(64位机) Visual Studio 2010 GDAL 1.9.2(我也尝试了最新版GDAL1.11.0,应该同样可以用的,只是在重新配置时又选用了老一点的版本 ...

  6. (转)mysql的sql_mode合理设置

    mysql的sql_mode合理设置 目录          http://xstarcd.github.io/wiki/MySQL/MySQL-sql-mode.html http://dev.my ...

  7. ElasticSearch-SQL 安装和使用

    ES上线之后,用lucene语法来查询数据,学习成本略高,所以考虑用es-sql来简化这部分的操作. ES版本:5.4.0,节点部署如下: master node:3 client node:2,po ...

  8. css 中 stick footer 布局实现

    做项目中,我们在写弹框的时候,不管弹框的内容多或者少,可能需要一些内容需要固定在框底部,比如关闭按钮.stick footer 就是让 footer 元素固定在底部 当内容不足满屏时,footer 紧 ...

  9. Python -- 数据结构实现

    1.堆栈(pyStack.py) class PyStack: def __init__(self, size=20): self.stack = [] self.size = size self.t ...

  10. NoSQL之Redis入门笔记

    Redis 1.Redis介绍 1.1 NoSQL:一类新出现的数据库(not only sql),它的特点 不支持sql语法 存储结构跟传统关系型数据库中的那种关系表完全不同,nosql中存储的数据 ...