利用 axios 设置哀求带上cookie
import axios from 'axios'axios设置 withCredentials
1. 在全局设置
axios.defaults.headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'withCredentials':true
}
2. 在实例上设置
// 创建axios实例
const service = new axios.create({
'withCredentials':true
})
3. 在请求时设置
axios.post(api_url, data, {'withCredentials':true}).then(function (res) {
console.log(res)
}).catch(function (e) {console.log(e)})
服务端响应头设置
响应需要携带响应头 Access-Control-Allow-Credentials: true
https://img-blog.csdnimg.cn/direct/15e261f0ed8749f8be91e6a35fc0dd6f.png#pic_center
响应头 Access-Control-Allow-Origin 不能是通配符"*" ,并且需要和请求头Origin 的值一致
https://img-blog.csdnimg.cn/direct/10e53774a6f54bf881d2ecd0fd856cb4.png#pic_center
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]