小程序websocket data中参数后台接收不到
发布于 7 年前 作者 yang54 17592 次浏览 来自 问答

后台使用的springmvc的websocket实现,但是wx_id始终是null

[@Override](/user/Override)

    public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse arg1, WebSocketHandler arg2,

            Map<String, Object> map) throws Exception {

        if (request instanceof ServletServerHttpRequest) {

            ServletServerHttpRequest servletRequest = (ServletServerHttpRequest) request;

            HttpServletRequest httpRequest = servletRequest.getServletRequest();

            HttpSession session = httpRequest.getSession();

            

            System.out.println(httpRequest.getParameter("wx_id"));  //为什么是null?????????

            if (session != null) {

                map.put("user_info", httpRequest.getParameter("wx_id"));

   }

        }

        System.out.println("连接到我了");

        return true;

    }


小程序代码:

wx.connectSocket({

url: ‘ws://127.0.0.1:8080/testSocket/webSocketServer.action’,

data: {

wx_id: ‘zzz’

},

header: {

‘content-type’: ‘application/json’

},

method: “GET”

});

1 回复

同样的问题

回到顶部