Axios won't send cookie, Ajax (xhrFields) does just fine

老子叫甜甜 提交于 2019-11-30 09:36:42

I was facing a similar issue. Making a get/post request through Axios did not sent the same headers as a straight XHR request.

Then I just added the following just after the Axios require statement:

axios.defaults.withCredentials = true;

After that Axios started sending my cookie like the regular XHR request did.

jinzo21

Working example using Danielo515's answer:

import * as axios from 'axios';
axios.defaults.withCredentials = true;


export function getAll() {
    const url = 'https://example.com';
    return axios.get(url);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!