再客户端调整成如上配置后,再次运行会报以下错误,见图3。
“Access to fetch at'https://webresource.c-ctrip.com/ResUnionOnline/R1/common/marinRedirect.js?v=20220903'from origin 'https://www.ctrip.com' has been blocked by CORS policy: 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'.”
图3 请求出错截图
通过翻阅这篇文章(Reason: Credential is not supported if the CORS header ‘Access-Control-Allow-Origin’ is ‘*’),我们可以得到解答:
“CORS 请求发出时,已经设定了 credentials,但服务端配置了 http 响应首部Access-Control-Allow-Origin 的值为通配符 ("*") ,而这与使用 credentials 相悖。”
所以,这才回到了本节一开始我们需要做的一个调整,将原先的Access-Control-Allow-Origin设置为具体的origin值,而非 * 星号。
再次调整之后,服务的响应头更新为图4所示: