When I send request with axios to my server from 3000 port to 8000 I got 403 forbidden error. But when I send reqest from postman I don't have this error. I am using withCredentials param. And I got csrf token, but when I am sending request on login page I am getting 403 forbidden. How I can get sessionid?
axios.get('http://localhost:8000/', {
withCredentials: true
})
.then((response) => {
// const cookies = response.headers['Set-Cookie']
console.log('res', response);
let csrf = document.cookie.split('=')[1]
console.log('cookie', document.cookie);
console.log(csrf);
axios.post('http://localhost:8000/', {
password: '12345678',
username: 'admin@admin.com',
csrfmiddlewaretoken: csrf
// csrfmiddlewaretoken: 'Njqa9oV5mWmT6fjJhqOYNu8cZ23LgPWK'
}, {
headers: {
// 'X-CSRFToken': csrf,
// 'csrftoken': csrf
// 'X-CSRFToken': 'Njqa9oV5mWmT6fjJhqOYNu8cZ23LgPWK',
// 'X-CSRFToken': csrf,
// 'Cookie': `csrftoken=${csrf}`
},
withCredentials: true
})
.then(res => {
console.log('post res', res);
console.log(document.cookie)
// axios.get('http://localhost:8000/api/devices/v2/thermostats/', {
axios.get('http://localhost:8000/api/devices/v2/thermostats/', {
headers: {
'X-CSRFToken': csrf,
},
withCredentials: true
})
.then(res => {
console.log('get', res);
})
})
});