您现在的位置是:主页 > news > 南山区住房和建设局官方网站/软件培训机构排名

南山区住房和建设局官方网站/软件培训机构排名

admin2025/5/20 23:12:22news

简介南山区住房和建设局官方网站,软件培训机构排名,网站热力图怎么做,免费网站建设绑定域名问题:请求的数据格式与后台要求的不匹配 思路:axios对比用jq的请求是成功的 axios请求: jq请求: 首先发现Request Payload和Form Data不同 解决:增加请求头 this.$http({method: "post",url: "/logi…

南山区住房和建设局官方网站,软件培训机构排名,网站热力图怎么做,免费网站建设绑定域名问题:请求的数据格式与后台要求的不匹配 思路:axios对比用jq的请求是成功的 axios请求: jq请求: 首先发现Request Payload和Form Data不同 解决:增加请求头 this.$http({method: "post",url: "/logi…

问题:请求的数据格式与后台要求的不匹配
思路:axios对比用jq的请求是成功的
axios请求:
在这里插入图片描述
jq请求:
在这里插入图片描述
首先发现Request Payload和Form Data不同
解决:增加请求头

this.$http({method: "post",url: "/login/xxx",data: this.ruleForm,headers: { "content-type": "application/x-www-form-urlencoded" },}).then((res) => {console.log(res);});

结果:
在这里插入图片描述
很多人到这就解决了,但是我的继续400,对比了一下jq的,应该不难用{}包裹,那就是必须要Form Data格式的数据了
使用formData包裹数据

let formData = new FormData();
formData.append('name',this.ruleForm.name);
formData.append('password',this.ruleForm.password);
this.$http({method: "post",url: "/login/checkLogin",data: formData,headers: { "content-type": "application/x-www-form-urlencoded" },
}).then((res) => {console.log(res);
});

最后成功
在这里插入图片描述
优化:
如果不想每次请求都手动改headers
那么就全局配置axios的headers

import axios from 'axios'
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
Vue.prototype.$http = axios``