Form表单编码格式

Form表单是HTML的标签,包含了很多组件,比如input、单选框和复选框等等;

背景介绍

  HTTP协议规定了POST提交的数据都必须在消息体Entity中,但是并没有明确规定Entity的编码格式,而是提供了一种灵活的方式:在请求头Content-Type中指定Entity的编码格式,接收方根据Content-Type解析消息体的内容;

编码格式

  Form表单提供了三种编码方式,用于对表单数据的编码,介绍如下。

application/x-www-form-urlencoded

  表单数据的格式与URL的查询字符串格式一样:key1=val1&key2=val2且被URL编码,如下所示:
在这里插入图片描述

multipart/form-data

  产生背景:在发送大量二进制数据或者包含非ASCII字符的文本时,application/x-www-form-urlencoded编码方式并不高效,因此multipart/form-data编码方式产生。
(https://tools.ietf.org/html/rfc2046#section-5.1);

  The encoding type application/x-www-form-urlencoded is inefficient for sending large quantities of binary data or text containing non-ASCII characters. Thus, a new media type, multipart/form-data, is proposed as a way of efficiently sending the values associated with a filled-out form from client to server.

  multipart含义:消息体的数据由多部分Part组成,Part间通过boundary分隔符分隔,每个Part包含元信息和数据两部分,具体见[rfc2046]

  具体格式:表单数据以表单控件为单位被分隔符boundary分隔成多个part,每个part包含content-disposition(form-data)、Content-Type(可选,默认为text/plain)以及name(控件名称的信息),如下图所示:
在这里插入图片描述

参考:

  1. 基于表单的文件上传:http://www.ietf.org/rfc/rfc1867.txt;
  2. multipart/form-data 文档:https://tools.ietf.org/html/rfc7578;
  3. multipart含义:https://tools.ietf.org/html/rfc2046#section-5.1;
  4. Content-type对照表:http://tool.oschina.net/commons?type=22013-05-17;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值