Spring websocket-客户端CORS政策错误

问题描述 投票:1回答:1

我正在使用websocket在服务器和客户端之间进行通信。我遵循此文档来实现websocket依赖性。现在,当我尝试通过示例客户端页面进行连接时,会产生以下错误:

Access to XMLHttpRequest at '....' from origin 'null' 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.

我已经尝试将.setAllowedOrigins("*")添加到WebSocketConfig,但是并不能解决此问题。解决方案是什么?

spring spring-websocket java-websocket
1个回答
0
投票

由于错误消息说您正在发送一个包含设置为包括的凭据的请求,我想您正在随请求发送某种令牌/访问数据。

这样做时,您的服务器必须以正确的来源进行响应。如果您正在开发中,请尝试设置本地主机。例如.setAllowedOrigins(“ http://localhost:8080”)或您正在使用的内容。在生产中,您需要用部署URL替换它。

© www.soinside.com 2019 - 2024. All rights reserved.