【问题标题】:how to add authorization header to IO.socket call in android如何在android中向IO.socket调用添加授权标头
【发布时间】:2017-11-24 08:45:55
【问题描述】:
 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
  }

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 我已经试过了,但是没用,兄弟请给个思路
    猜你喜欢
    • 1970-01-01
    • 2021-10-17
    • 2016-03-24
    • 2017-10-04
    • 1970-01-01
    • 2020-03-29
    • 2017-01-04
    • 2016-04-16
    • 1970-01-01
    相关资源
    最近更新 更多