Using cookies with Android volley library -


does know how attach session cookie request using com.android.volley library? when log in web site gives me session cookie. browser send cookie subsequent request. volley not seem that, @ least not automatically.

thanks.

volley doesn't make http requests itself, , doesn't manage cookies directly. instead uses instance of httpstack this. there 2 main implementations:

  • hurlstack: uses httpurlconnection under hood
  • httpclientstack: uses apache httpclient under hood

cookie management responsibility of httpstacks. , each handle cookies differently.

if need support < 2.3, should use httpclientstack:

configure httpclient instance, , pass volley use under hood:

// if need directly manipulate cookies later on, hold onto client // object gives access cookie store defaulthttpclient httpclient = new defaulthttpclient();  cookiestore cookiestore = new basiccookiestore(); httpclient.setcookiestore( cookiestore );  httpstack httpstack = new httpclientstack( httpclient ); requestqueue requestqueue = volley.newrequestqueue( context, httpstack  ); 

the advantage vs manually inserting cookies headers actual cookie management. cookies in store respond http controls expire or update them.

i've gone step further , sub-classed basiccookiestore can automatically persist cookies disk.

however! if don't need support older versions of android. use method:

// cookiestore interface, can implement , things // save cookies disk or ever. cookiestore cookiestore = new mycookiestore(); cookiemanager manager = new cookiemanager( cookiestore, cookiepolicy.accept_all ); cookiehandler.setdefault( manager  );  // optionally, can use default cookiemanager cookiemanager manager = new cookiemanager(); cookiehandler.setdefault( manager  ); 

httpurlconnection query cookiemanager implicitly. httpurlconnection more performant , bit cleaner implement , work imo.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -