xebia-functional/appsly-android-rest

How do I get the cookie set by the server?

Closed this issue · 1 comments

I tried this out and I must say that this works absolutely great!

I have one query though. How do I get the cookie set by the server?

I have an app that uses this library. I have an authentication function on the server that sets a JSESSIONID on the client after successful login. I see that the cookie is set in every request I send out to the server from this library. But I also have a webview that needs to have that cookie.

I normally set the cookie on the webview by using the following lines of code:

CookieSyncManager syncManager = CookieSyncManager.getInstance();
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setCookie("www.MyBaseUrl.com", httpUrlConnection.getHeaderField("Set-Cookie")); // Here your cookie
syncManager.sync();

Could you please let me know how I can get the cookie? @raulraja

@akshaybhasme you can obtain the headers out of the response object like so:

new TestCallback<T> extends Callback<T> {            
    @Override
     public void onResponse(Response<T> response) {
        response.getHeaders()
     }
}