1、400状态码
400的主要有两种形式:
(1)、bad request意思是“错误的请求";
(2)、invalid hostname意思是"不存在的域名”。
2、axios
axios默认的请求头的格式是:
application/json
若后端的请求头是:
application/x-www-form-urlencoded
application/x-www-form-urlencoded表示:
数据被编码为名称/值对。这是标准的编码格式。
若前端发送post请求时的参数以json格式发送就会报400,
this.$http.post({ url:'/v1/assets', data:{ name: this.form.name, categoryType: this.form.type, categoryName: this.form.type === "power" ? "电源" : "其他配件", fee: 123.5, factoryId: 1 }
修改方法:对请求的参数进行 序列化成URL形成发送。
使用qs库的qs.stringify方法即可。