Can "Upgrade" only to "WebSocket".是为什么?
                            2025-6-18 23:26:01
                            
                            
                            
                        
                        直接用浏览器访问链接的时候提示 Can "Upgrade" only to "WebSocket". ,其实就是405,request method 和预期的不一样。这时候要换成ws://即可或者安全为wss://开头即可。
  js  请求可以用  websocket  的  js  库更方便,Java用 SSLWebSocketClient
new SSLWebSocketClient(new URI("wss://www.sojson.com/detect"),domian, cacheKey) {
     @Override
     public void onClose(int arg0, String arg1, boolean arg2) {
         log.info("{},检测:正常关闭", domian);
     }
     @Override
     public void onError(Exception e) {
         log.info("{},检测,异常", domian,e);
         updateDtoInfo("{\"action\":\"ERROR\",\"code\":\"200\"}", cacheKey);
         this.close();
     }
     @Override
     public void onMessage(String message) {
         updateDtoInfo(message,cacheKey);
     }
     @Override
     public void onOpen(ServerHandshake arg0) {
         //发送查询
         this.send(this.getInitMessage());
     }
}.connect();版权所属:JavaScript加密
原文地址:https://www.jsjiami.com/article/only-to-websocket-.html
转载时必须以链接形式注明原始出处及本声明。
                                    本文标签:
                                    
                                
                         
        