简体   繁体   English

在 axios 请求中添加 CSRF TOKEN

[英]adding CSRF TOKEN in axios request

how can I set CSRF TOKEN in my axios request, I've tried this如何在我的 axios 请求中设置 CSRF TOKEN,我试过这个

 // 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).但我仍然收到 403 错误(禁止)。 Do I have to include something else?我必须包含其他内容吗?

Authorization: ${tokenApp}授权: ${tokenApp}

probably needs to be:可能需要:

Authorization: Bearer ${tokenApp}授权: 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.但是,如果没有关于服务器端的详细信息、您使用的框架以及有关如何在服务器端实际设置身份验证的一些信息,除了猜测之外,没有办法确定哪里出了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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