- f12这样报错:Access to XMLHttpRequest at '
- http://localhost:8080/users/signup' from origin '
- http://127.0.0.1:5500' has been blocked by CORS policy: 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'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
前端请求可能设置了withCredentials: true
,这要求服务器必须明确指定允许的源,而不能使用通配符。为解决这个问题,请按照以下步骤操作:
- 需要在API服务器上配置CORS,以明确指定允许的前端域名(在这个案例中是
http://127.0.0.1:5500
),而不是使用*
。