如何在android中添加授权头到IO.socket调用

时间:2017-06-21 12:31:50

标签: android sockets android-studio sails.js io-socket

 JSONObject getobj = new JSONObject();

        postobj.put("url", String.format("/user"));

        Log.d("Get MEthod", getobj.toString() + ">>>>>>>>>>>>>>>>>>>>Get Message " + socket.connected());

        Log.d(TAG, " the meessage url " + getobj.toString());

        socket.emit("get",getobj, new Ack() {
            @Override
            public void call(Object... args) {

                JSONObject obj = (JSONObject) args[0];

                Log.d("GET CHAT MEESSAGE ", obj.toString() + ">>>>>>>>>>>>>>>>>>>> with in call method Get Message " + socket.connected());

            }
        });

/ 我收到了Bellow回复 \

   {
   "body": {
      "err": "No Authorization header was found"
     },
   "headers": {

   },
   "statusCode": 401
  }

1 个答案:

答案 0 :(得分:0)

这是我为Socket连接添加授权令牌的方式,希望这有帮助

IO.Options options = new IO.Options(); 
options.forceNew = true;                        
options.reconnectionAttempts = Integer.MAX_VALUE;                    
options.timeout = 10000;    
options.query = "token=" + "your_authorization_code";