websocket failed: Error during WebSocket handshake: Unexpected response code: 200

websocket+spring整合,不能访问,

解读源码:

原因:websocket_username=null,导致空异常

解决:给websocket session 添加用户名

//握手前,读取用户名,并赋值给websocket的session
    @Override
    public boolean beforeHandshake(ServerHttpRequest request,
            ServerHttpResponse response, WebSocketHandler handler,
            Map<String, Object> attr) throws Exception {
         if (request instanceof ServletServerHttpRequest) {
                ServletServerHttpRequest servletRequest = (ServletServerHttpRequest) request;
                HttpSession session = servletRequest.getServletRequest().getSession(false);
                if (session != null) {
                    String userName = (String) session.getAttribute(Constants.SESSION_USERNAME);
                    if(userName == null){
                        userName = "WEBSOCKET_USERNAME_IS_NULL";
                    }
                    attr.put(Constants.WEBSOCKET_USERNAME,userName);
                }
            }
        return true;
    }
时间: 2024-08-11 05:34:47

websocket failed: Error during WebSocket handshake: Unexpected response code: 200的相关文章

nginx反向代理 报错:Error during WebSocket handshake: Unexpected response code: 403

遇到nginx报错:websocket wss failed: Error during WebSocket handshake: Unexpected response code: 403 server { listen 6340; location / { proxy_pass http://web; proxy_http_version 1.1; #Nginx在与Node后端通信时使用HTTP/1.1,是WebSockets所必需的 proxy_set_header Origin '';

struts2+websocket报错:failed: Error during WebSocket handshake: Unexpected response code:404

最近把websocket集成进项目里面来,打开网页总是会遇到这样的错误. 网上说的原因有3种,但是都不适合我,但是也记录下. 1.struts2截拦掉了ws的请求.这种援用可以尝试把web.xml清空,如果可以连接,则是这个问题.此时在struts.xml的配置文件中添加: <constant name="struts.action.excludePattern" value="ws://*"></constant> 对ws的请求不截拦. 2

Socket.IO failed: Error during WebSocket handshake:

在node安装了Socket.IO,做demo时报错 WebSocket connection to 'ws://localhost:8999/socket.io/?EIO=3&transport=websocket&sid=D0fxLuPwjHWgYSI7AAAB' failed: Error during WebSocket handshake: Unexpected response code: 400 WebSocket 握手时发生错误,诡异的是我前端页面没有关闭,重启服务器nod

报错nginx failed error: during websocket handshake

location / {proxy_pass http://localhost:8080;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_set_header Host $host;}

Failed: error processing document #281: unexpected EOF,往MongoDB当中插入json文件时出现的错误。

往MongoDB当中插入json文件时提示的错误(我的操作系统是win10): 当时的执行命令是:mongoimport -d test -c restaurants d://primer-dataset.json 之后将 primer-dataset.json文件存入文件夹当中就可以成功插入了,执行命令为:mongoimport -d test -c restaurants d://mongoDB/primer-dataset.json 成功提示如下: 个人感觉是应该是路径选择出现的问题,我把

vue-cli 安装失败Failed to download repo vuejs-templates/webapck-simple: Response code 404 (Not Found)

新学习vue的萌新们经常会遇到各种各样的坑.例如上面这个报错.这个一般是命令行面板写错单词导致. 正确:vue init webpack-simple .(注意"."点,指当前目录) 正确2:veu init webapck project(project自己取得名字): 在安装之前,请确保在命令行输入vue -V(大写V) node -v(小写v)能输出版本号 并且命令行输入"ping github.com"能连接得上.连接不上也无所谓,百度淘宝镜像,按照要求装个

soket.io 客户端连接出现 response code: 400 的解决办法

书中提到使用 npm install socket.io 安装 node.js 的 soket.io 模块 默认安装的为最新版本  可以使用 npm list 查看当前装了哪些模块 如果出现 SIOClientImpl::handshakeResponse() called handshake completedresponse code: 400SIOClientImpl::handshake() failederror buffer: HelloWorld::onError received

Error Domain=com.alamofire.error.serialization.response Code=-1016 &quot;Request failed: unacceptabl

在使用AFNetworking 2.0  的时候本来一切很顺畅,但是中途遇到几个比较坑的地方 这里分享一下爬坑经历,忘读者不能速爬坑! 在发送请求后,NSURLSessionDataTask一直报错 Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" AFURLResponseSerializat

Error Domain=com.alamofire.error.serialization.response Code=-1016 &quot;Request failed: unacceptable content-type: text/html&quot; 的问题原因及解决方案

Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html",此问题的原因就是使用的第三方框架AFNetworking 接口返回值类型不确定,由于服务器人员习惯于使用html文件所以将json文件也这么写了,导致没法解析 在模型类或者网络工具类中添加这句代码就能完美解决上述问题,建议不要直接修改AFNetw