Socket.io-client-java: Headers Authentification

Created on 13 Oct 2015  路  4Comments  路  Source: socketio/socket.io-client-java

Hi,

I use Sails and socket.io. I try to use your lib to connect my Android application with my server but I have a 403 cause I'm not login. How can I send the correct header to be logged with this library. I didn't find anything on the doc about this.

All 4 comments

An example of accessing http headers. I noted this on READEME.

socket.io().on(Manager.EVENT_TRANSPORT, new new Emitter.listener() {
  @Override
  public void call(Object... args) {
    Transport transport = (Transport)args[0];

    transport.on(Transport.EVENT_REQUEST_HEADERS, new Emitter.Listener() {
      @Override
      public void call(Object... args) {
        @SuppressWarnings("unchecked")
        Map<String, List<String>> headers = (Map<String, List<String>>)args[0];
        // modify request headers
        headers.put("Cookie", Arrays.asList("foo=1;"));
      }
    });

    transport.on(Transport.EVENT_RESPONSE_HEADERS, new Emitter.Listener() {
      @Override
      public void call(Object... args) {
        @SuppressWarnings("unchecked")
        Map<String, List<String>> headers = (Map<String, List<String>>)args[0];
        // access response headers
        String cookie = headers.get("Set-Cookie").get(0);
      }
    });
  }
});

Thanks ^^ it's perfect ! No more 403 ^^

Does this still apply on newer version? @nkzawa

yes it does

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jukbot picture jukbot  路  3Comments

arpitjoshi08 picture arpitjoshi08  路  3Comments

hova4 picture hova4  路  12Comments

pareshdevatval picture pareshdevatval  路  4Comments

mrgame64 picture mrgame64  路  10Comments