前端代码
//var url="http://192.168.8.222:88/mi/connectServer"
var socket = new SockJS(url);
stompClient = Stomp.over(socket);
stompClient.connect({
Referer:""
}, function(frame) {
// setConnected(true);
console.log(randomCode);
stompClient.subscribe('/getMessage/' + randomCode + '/message',function(greeting){
var msg = JSON.parse(greeting.body);
console.log(JSON.parse(greeting.body));
if(msg.codeNum==0){
mui.openWindow("pay-success.html?msg="+greeting.body)
}else {
mui.openWindow("pay-fail.html")
}
});
});
后台代码
public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
//在网页上可以通过"/applicationName/hello"来和服务器的WebSocket连接
stompEndpointRegistry.addEndpoint("/mi/connectServer").setAllowedOrigins("*").withSockJS();
}
主要是前后端分离 出现这个问题
Access to XMLHttpRequest at 'http://mms-server.swxc.com/mi/connectServer/info?t=1561973806317' from origin 'http://192.168.8.222:5000' 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.
SockJS连接跨域问题 报错
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- Smile Taotao cium 2019-07-01 19:39关注
自己有个CORSInterceptor 拦截器 response.addHeader("Access-Control-Allow-Origin", “*”);
修改为
response.addHeader("Access-Control-Allow-Origin", request.getHeader("origin"));
response.addHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
就好了本回答被题主选为最佳回答 , 对您是否有帮助呢?解决评论 打赏 举报无用 2
悬赏问题
- ¥15 网站出现错误跳转问题
- ¥15 Docker容器里已经安装了ssh,但打包迁移到新机器一直容器一直提示unrecognized service。
- ¥15 综合布线实例设计,就好看好看不恐怖可好滤镜好聚
- ¥15 使用moviepy库视频合并时出错
- ¥30 FLUENT液固传质UDF
- ¥15 怎么看梯度直方图以,怎么判断梯度消失/爆炸,怎么解决
- ¥15 aspnetdll文件访问拒绝
- ¥15 wpf中在模版中寻找元素
- ¥15 MFC平台生成指定圆
- ¥15 jmeter出现403