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

相關文章
相關標籤/搜索