在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ axios 創(chuàng)建實(shí)例后 put 請(qǐng)求時(shí)無法攜帶設(shè)置的請(qǐng)求頭

axios 創(chuàng)建實(shí)例后 put 請(qǐng)求時(shí)無法攜帶設(shè)置的請(qǐng)求頭

在創(chuàng)建axios實(shí)例代碼之后,分別設(shè)置了post,put,同時(shí)設(shè)置了共通請(qǐng)求頭application/x-www-form-urlencoded;charset=UTF-8.使用post請(qǐng)求攜帶了自定義設(shè)置的請(qǐng)求頭,但是使用put后,請(qǐng)求就不會(huì)攜帶設(shè)置的請(qǐng)求頭。并且出現(xiàn)了跨域的問題.
代碼如下:

const instance = axios.create({
baseURL: process.env.BASE_API,
timeout: 5000,
withCredentials: true,
headers: {
'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'
}
})

function put (url, putData) {
return instance.put(url, qs.stringify(putData))
}

function post (url, postData) {
 return instance.post(url, qs.stringify(postData))
}

export default {
 get: get,
 post: post,
 put: put
}

post的請(qǐng)求
clipboard.png
put請(qǐng)求
clipboard.png

回答
編輯回答
陪我終

PUT方法不屬于簡單請(qǐng)求, 瀏覽器會(huì)先發(fā)一次options, 詢問服務(wù)器

2017年2月11日 17:28
編輯回答
尤禮

我估計(jì)是axios封裝的post,put方法里面也設(shè)置請(qǐng)求頭,你試一下不用封裝的方法,直接用axios()試試

2017年12月16日 23:58
編輯回答
孤巷

這個(gè)不是put的請(qǐng)求頭 是options的請(qǐng)求頭
當(dāng)請(qǐng)求是put所以已經(jīng)不是非簡單請(qǐng)求了 要先發(fā)送一個(gè)預(yù)檢的options請(qǐng)求
看見有個(gè)字段 Access-Control-Request-Method: PUT 這句話就是問服務(wù)器是否支持PUT的跨域請(qǐng)求

2017年12月5日 14:49