Vue 加入 withCredentials 后无法进行跨域请求?

Vue和django的前后端分离项目,之前通过在django中允许跨域访问实现了跨域请求,但为了使每个请求带上session信息,我设置了withCredentials ,即:

axios.defaults.withCredentials = true

然后跨域请求时会出现如下问题:

Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:8080' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

请问有人知道是什么问题吗?

阅读 16.3k
2 个回答

服务端要做以下2个工作:

  1. Access-Control-Allow-Origin 字段必须指定域名,不能为*

  2. Access-Control-Allow-Credentialstrue

后台支持options请求吗

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题