鍍金池/ 問(wèn)答/HTML/ Vue 加入 withCredentials 后無(wú)法進(jìn)行跨域請(qǐng)求?

Vue 加入 withCredentials 后無(wú)法進(jìn)行跨域請(qǐng)求?

Vue和django的前后端分離項(xiàng)目,之前通過(guò)在django中允許跨域訪問(wèn)實(shí)現(xiàn)了跨域請(qǐng)求,但為了使每個(gè)請(qǐng)求帶上session信息,我設(shè)置了withCredentials ,即:

axios.defaults.withCredentials = true

然后跨域請(qǐng)求時(shí)會(huì)出現(xiàn)如下問(wèn)題:

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.

請(qǐng)問(wèn)有人知道是什么問(wèn)題嗎?

回答
編輯回答
孤巷

后臺(tái)支持options請(qǐng)求嗎

2017年10月29日 12:31
編輯回答
舊顏

服務(wù)端要做以下2個(gè)工作:

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

  2. Access-Control-Allow-Credentialstrue

2018年3月15日 22:46