axios post 400 状态码

一、400状态码前端

400的主要有两种形式:
(1)、bad request意思是“错误的请求";
(2)、invalid hostname意思是"不存在的域名”。
 
二、axios
axios默认的请求头的格式是:
application/json

若后端的请求头是:ios

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造成发送。json

使用qs库的qs.stringify方法便可。axios

相关文章
相关标签/搜索