一直以来在ajax获取数据的时候分不清Content-Type不同的区别,今天分别用Content-Type: 'application/json;charset=UTF-8',和Content-Type:application/x-www-form-urlencoded的调通了接口,记录一下。
当使用Content-Type: 'application/json;charset=UTF-8'
请求的参数是JSON格式的:
dataRequest: function(currPage) {
var data= {
xzqhcode: self.xzqhcode || '320582',
condition: {
properties: {},
sex: '', //2女,1男
populationtype: "", //1本地,4外籍
BIRTHCITYCODE: "", //籍贯
BIRTHDAY_more: "", //出生日期开始
BIRTHDAY_less: "" //出生日期结束
},
pagesize: 20,
pageindex: currPage
}
console.log(JSON.stringify(data));
return JSON.stringify(data);
},
chrome调试显示:

对应的在Postman中是使用raw来传参:

当使用默认的方式即Content-Type:application/x-www-form-urlencoded
请求的参数是以form-data的格式传的:
dataRequest: function(currPage) {
var data = {
xzqhcode: self.xzqhcode||'320582',
condition: {
"properties": {},
"sex": '',//2女,1男
"populationtype": "",//1本地,4外籍
"BIRTHCITYCODE": "",//籍贯
"BIRTHDAY_more": "",//出生日期开始
"BIRTHDAY_less": ""//出生日期结束
},
pagesize:10,
pageindex:currPage
}
var requestData = {
params: JSON.stringify(data)
}
console.log(requestData);
return requestData;
}
chrome调试显示:

对应的在Postman中是使用form-data来传参:

;
相应的接口获取我们传参的方式也不同:


网友评论