http 请求参数之Query String Parameters、Form Data、Request Payload
Query String Parameters
当发起一次GET请求时,参数会以url string的形式进行传递。即?
后的字符串则为其请求参数,并以&
作为分隔符。
如下http请求报文头:
// General
Request URL: http://foo.com?x=1&y=2
Request Method: GET
// Query String Parameters
x=1&y=2
Form Data
当发起一次POST请求时,若未指定content-type,则默认content-type为application/x-www-form-urlencoded。即参数会以Form Data的形式进行传递,不会显式出现在请求url中。
如下http请求报头:
// General
Request URL: http://foo.com
Request Method: POST
// Request Headers
content-type: application/x-www-form-urlencoded; charset=UTF-8
// Form Data
x=1&y=2
Request Payload
当发起一次POST请求时,若content-type为application/json,则参数会以Request Payload的形式进行传递(显然的,数据格式为JSON),不会显式出现在请求url中。
如下http请求报头:
// General
Request URL: http://foo.com
Request Method: POST
// Request Headers
content-type: application/json; charset=UTF-8
// Request Payload
x=1&y=2
如果希望通过Form Data的方式来传递数据,则可以通过原生方法formData()来进行数据组装,且content-type需要设置为multipart/form-data。
如下http请求报头:
// General
Request URL: http://foo.com
Request Method: POST
// Request Headers
content-type: multipart/form-data; charset=UTF-8
// Request Payload
------WebKitFormBoundaryAIpmgzV8Ohi99ImM
Content-Disposition: form-data; name="x"
1
------WebKitFormBoundaryAIpmgzV8Ohi99ImM
Content-Disposition: form-data; name="y"
2
------WebKitFormBoundaryAIpmgzV8Ohi99ImM--
其中,WebKitFormBoundaryAIpmgzV8Ohi99ImM
为浏览器随机生成的boundary
,作为分隔参数,作用等同于&
。
application/x-www-form-urlencoded 和 multipart/form-data
The content type "application/x-www-form-urlencoded" is inefficient for sending large quantities of binary data or text containing non-ASCII characters. The content type "multipart/form-data" should be used for submitting forms that contain files, non-ASCII data, and binary data.
multipart/form-data
的优势还伴随一些兼容性问题,详细请参考文章结束的参考文献。
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
当我们使用ajax去异步请求数据时,会发现通过$.POST处理时数据出现在请求体的form-data,而用$.AJAX去异步请求数据时,数据出现在请求体的request payload。
GET、POST方式提交的请求:
Content-type:
1、application/x-www-form-urlencoded:@RequestBody不是必须加的
2、mutipart/form-data:@RequestBody不能处理这种格式
3、其他格式,比如application/json,application/xml等,必须使用@RequestBody来处理
PUT方式提交的请求:
以上1和3的场景都是必须使用@RequestBody来处理的,2场景也是不支持的
http 请求参数之Query String Parameters、Form Data、Request Payload的更多相关文章
- HTTP请求中的form data,request payload,query string parameters以及在node服务器中如何接收这些参数
http://www.cnblogs.com/hsp-blog/p/5919877.html 今天,在工作(倒腾微信小程序)的时候,发现发送post请求到node后台服务器接收不到前端传来的参数.其实 ...
- asp.net query string 及 form data 遇到的编码问题
当遇到此问题时,脑海里闪过的第一个解决方案是设置 web.config 的编码.但一想,就某一个页面的需求而导致其他跟着妥协,不是好的解决方案.于是网上搜索答案,下面做个小分享,遗憾的是研究不够深入, ...
- springMVC接收参数的区别form data与query string parameters与request payload
在AJAX请求中,我见过有三种form表单数据类型提交. 第一种:form data, 第二种:query string parameters,第三种:request payload. 在google ...
- query string parameters 、 Form Data 、 Request Payload
微信小程序ajax向后台传递参数的时候总是报400错误 然后看了一下network 发现是query string parameters,但是我写的header如下 header:{ "Co ...
- jmeter发送Query String Parameters格式参数报错
当发起一次GET请求时,参数会以url string的形式进行传递.即?后的字符串则为其请求参数,并以&作为分隔符 当参数为json格式时,这时需要勾选编码,否则会报错
- getParameterMap()的返回值为Map<String, String[]>,从其中取得请求参数转为Map<String, String>的方法如下:
直接遍历报错:[Ljava.lang.String;@44739f3f Map<String, String> tempMap = new HashMap<String, Strin ...
- <原>ASP.NET 学习笔记之HTML helper中参数何时会是路由参数,何时又会是query string?
HTML helper中参数何时会是路由参数,何时又会是query string? @Html.ActionLink("Edit", "Edit", new ...
- HTTP请求中的form data和request payload的区别
HTML <form> 标签的 enctype 属性 在下面的例子中,表单数据会在未编码的情况下进行发送: <form action="form_action.asp&qu ...
- AJAX POST请求中参数以form data和request payload形式在servlet中的获取方式
转载:http://blog.csdn.net/mhmyqn/article/details/25561535 HTTP请求中,如果是get请求,那么表单参数以name=value&name1 ...
随机推荐
- java程序的种类有三种
Application―Java应用程序”是可以独立运行的Java程序.由Java解释器控制执行.Applet ―Java小程序”不能独立运行(嵌入到Web页中). 由Java兼容浏览器控制执行. ...
- Standard Series Values in a Decade for Resistances and Capacitances E24 E48 E96
E3 50% tolerance (no longer used)E6 20% tolerance (now seldom used)E12 10% toleranceE24 ...
- EasyUI学习总结(五)——EasyUI组件使用
一.EasyUI组件的简单介绍 easyUI提供了很多组件让我们使用,如下图所示:
- 解决Cordova开发的iOS的app界面被状态栏覆盖
解决方法如下: 一:在MainViewController.m中添加如下代码: -(void)viewWillDisappear:(BOOL)animated { if([[[UIDevice cur ...
- caffe出错:Unknown bottom blob 'data' (layer 'conv1', bottom index 0)
原文https://blog.csdn.net/u011070171/article/details/75425740 caffe训练出现如下错误: Unknown bottom blob 'data ...
- CentOS7 下 keepalived 的安装和配置
安装前准备:yum -y install gcc gcc-c++ autoconf automake make yum -y install zlib zlib-devel openssl opens ...
- 基于Python项目的Redis缓存消耗内存数据简单分析(附详细操作步骤)
目录 1 准备工作 2 具体实施 1 准备工作 什么是Redis? Redis:一个高性能的key-value数据库.支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进行使 ...
- LeetCode Permutations问题详解
题目一 permutations 题目描述 Given a collection of numbers, return all possible permutations. For example,[ ...
- Swift 静态派发和动态派发
前言 方法是 Swift 中的一个重要概念,方法允许你把需要复用的代码封装进方法中,这样当你调用方法时,实际上你的想法是执行方法中的那些代码,方法的出现极大的提高了方法的复用性. Swift 工程的环 ...
- Kubernetes的ConfigMap解析
ConfigMap功能在Kubernetes1.2版本的时候就有了,许多应用程序会从配置文件.命令行参数或环境变量中读取配置信息.这些配置信息需要与docker image解耦,你总不能每修改一个配置 ...