Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Cookies with Robospice Retrofit requests

Can anyone please suggest me a way to manage cookies in robospice retrofit type HTTP requests.

I have a authentication system which has a login , a few GET HTTP requests , and a logout.

During login i need to save the session and use the same session for the rest GET HTTP requests and when I logout the session has to be cleared.

Here the login is a HTTP POST request which sends and recieves data through JSON format. I am using robospice retrofit as it easily manages the login and logout requests.

like image 366
Revanth Gopi Avatar asked Jun 27 '14 18:06

Revanth Gopi


1 Answers

You can set system-wide cookie-handler via java.net.CookieManager

CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cookieManager);

in your custom Application class.

To clear cookies after logout you can use method like this

public void clearCookies() {
    cookieManager.getCookieStore().removeAll();
}
like image 99
colriot Avatar answered Sep 26 '22 09:09

colriot