HTTP请求中的Form Data与Request Payloa

2020-06-15  本文已影响0人  salt丶

问题:后端用request.getParameter(""); 方法无法获取ajax传递的参数。

问题Js:

$.ajax({
url: url,
type: "post",
data: {
},
dataType: "json",
contentType: 'application/json;charset=utf-8'
});
###修改为
$.ajax({
url: url,
type: "post",
data: {
},
dataType: "json",
contentType: 'application/x-www-form-urlencoded;charset=utf-8'
});

排查过程:
以为json格式传递时,在chrome network 中请求头中参数传递的格式是Request Payload
以为x-www-form-urlencoded格式传递时,在chrome network 中请求头中参数传递的格式是Form Data
经查询得知,Request Payload在后端可以使用getRequestPayload方法来获取。Form Data后端可以通过request.getParameter(name)的形式来获取表单参数。

借鉴简书地址:https://www.jianshu.com/p/dab2f33c958a

上一篇 下一篇

猜你喜欢

热点阅读