简体   繁体   中英

adding CSRF TOKEN in axios request

how can I set CSRF TOKEN in my axios request, I've tried this

 // axios.defaults.xsrfCookieName = 'csrftoken';
// axios.defaults.xsrfHeaderName = 'X-XSRF-TOKEN';
const tokenApp = window.localStorage.getItem('token')
const {data: res} = await axios.post(`${URL}`, formData,
  {  withCredentials:true, xsrfHeaderName:'X-XSRF-TOKEN',headers: { Authorization: `${tokenApp}`,"Content-Type": "multipart/form-data" }});
  
  res.file = `http://20.88.238.192/azure-storage/api/blob/download/?file=${res.nameFile}`;
  return res;};

but i'm still getting 403 error (forbidden). Do I have to include something else?

Authorization: ${tokenApp}

probably needs to be:

Authorization: Bearer ${tokenApp}

But without details on your server side, what framework you are using, and some information about how the authentication is actually setup on the server side, there's no way, apart from guessing, to determine what is wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM