全部。我是 Spring Boot 和 Websocket 的新手。这是我的第一个集成 React 和 Spring Boot 项目,我目前正在使用 WebSocket 构建一个带有后端的聊天应用程序。
如前所述,我的前端是在 React (localhost:3000) 中构建的,但是当尝试调用后端/聊天应用程序时,我收到错误:
Access to XMLHttpRequest at 'http://localhost:9090/ws/info?t=1652731448126' from origin 'http://localhost:3000' 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'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
Run Code Online (Sandbox Code Playgroud)
我尝试查找一些可能的解决方案,例如使用@CrossOrigin(origins = "https://localhost:3000")and@CrossOrigin(origins = "http://localhost:3000")但这并没有改变任何东西。我也尝试过(@CrossOrigin(origins = "*") …