大多數的web服務器只能識別form的post的請求,即請求頭Content-Type為’application/x-www-form-urlencoded‘
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'這個試了沒有用
直接在
請求攔截進行添加
axios.interceptors.request.use(config => {
config.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
return config
}, error => {
return Promise.reject(error)
})
但是在發送請求時任然有問題,會把傳遞的參數直接作為對象鍵值就像這樣 {params}:(params為一個對象)
所以通過引入qs轉化一下
import qs from 'qs'
Vue.prototype.qs = qs
_this.axios.post(_url, this.qs.stringify(params)).then((res) => {
}).catch((err) => {
})