關於axios的post請求主要講三點:
1、post請求和get請求的區別:
get把參數包含在URL中,post通過request body傳遞參數
在傳參時,get使用params,post使用data
2、請求頭:headers
默認的請求頭:Content-Type:application/x-www-form-urlencoded
后端限制傳遞的必須為json數據時的請求頭:Content-Type:application/json
詳細了解見博客:
3、http協議的Form Data 和 Request Payload
Request Payload:請求頭部為 Content-Type: application/json
,並且請求正文是一個 json 格式的字符串
Form Data:請求頭部的 Content-Type: application/x-www-form-urlencoded
,並且請求正文是類似 get 請求 url 的請求參數
qs.stringify()用於將json類型的數據轉換為URL請求參數的形式