跨域请求 withCredentials 为 True 时,服务器允许的域名设置
当请求中设置 'withCredentials' 为 'True' 时,服务器返回的 'Access-Control-Allow-Origin' header 的值只能是一个域名、一个 '*'(表示允许任意域名),或者不设置该 header。
举一个例子,如果服务器希望允许 'https://example.com' 和 'https://test.com' 这两个域名进行跨域请求并携带凭证,可以返回以下响应头:
Access-Control-Allow-Origin: https://example.com
Access-Control-Allow-Credentials: true
这样,只有来自 'https://example.com' 和 'https://test.com' 的请求才能成功访问该资源,并可以携带凭证信息。
原文地址: https://www.cveoy.top/t/topic/pmt1 著作权归作者所有。请勿转载和采集!