DheveloperDhapare
DheveloperDhapare

Reputation: 15

vue.js and axios using but unable to receive set-cookie in response.headers

I tried to call external api from Vue js coreui theme but unable receive set-cookie in response.headers

Code is as below

axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
  axios.defaults.headers.common['Access-Control-Allow-Credentials'] = true;
  axios.defaults.headers.common['Access-Control-Allow-Origin'] = 'http://127.0.0.1:8000';
  axios.defaults.headers.common['Access-Control-Allow-Headers'] = 'X-PINGOTHER, Content-Type';
  axios.defaults.headers.common['Access-Control-Expose-Headers'] = 'Access-Token, Uid';
  axios.defaults.headers.common['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS';
    axios
    .post('url', 
    {
        par : '20'
    }, {
        withCredentials: true,
        })
    .then(function(response){
      console.log(response);
    })
    .catch(error => console.log(error))

I tried to use both

axios.defaults.headers.common['Access-Control-Expose-Headers'] = 'Access-Token, Uid';

this and

withCredentials: true,

Response is coming correct but headers not coming different

response.headers in console

in developer tools as bellow: developer tools response header

Note: On Postman I get the set-cookie but on application in response not getting.

I tried each and everything related Axios and Vue js but still not getting set-cookies in headers.

Upvotes: 0

Views: 4796

Answers (1)

BadPiggie
BadPiggie

Reputation: 6359

Actually you are confusing the request & response together. As @jonrsharpe said in comment section, The headers start with the prefix Access-Control- are Response Headers, Which means it should be sent by the server to browser in response. But here you are sending it to server from client.

You should enable it in your server side application. Not in client side.

Refer this, Set-Cookie not working in browser but works with Postman

Upvotes: 1

Related Questions