Android 4.4 KitKat not receiving cookies -


in application send post request server, , receive response server. , response gather different cookies, user information specifically. so, send login request , receive cookies after server responds, persist login. in android 4.3 , below, receive cookies fine , user logs in successfully. in android 4.4, user logs successfully, no cookies being received.

has android changed significant occur? here code below if has suggestions.

private url urlobj; private httpurlconnection connection; private dataoutputstream dataos;   private arraylist<string> schools; private arraylist<post> schoolposts; private string schoolid; private string name;  private string userlogincookie, sessionseedcookie, sessionuidcookie, sprefcookie;  private context context; private cookiestore store;  public dataparser(context _context) {     context = _context; }  //first call whenever connecting across user's network private void establishconnection() throws ioexception {     urlobj = new url(url);     connection = (httpurlconnection) urlobj.openconnection();     cookiemanager cookiemanager = new cookiemanager();      cookiemanager.setcookiepolicy(cookiepolicy.accept_all);     cookiehandler.setdefault(cookiemanager);     store = cookiemanager.getcookiestore();      getcookies();     connection.setrequestmethod("post");     connection.setrequestproperty("content-type","application/x-www-form-urlencoded");     connection.setrequestproperty("cookie", sessionseedcookie+";"+sessionuidcookie+";"+userlogincookie+";"+sprefcookie);     connection.setdooutput(true);     connection.setusecaches(false);      dataos = new dataoutputstream(connection.getoutputstream()); }  //called after communication complete private void disconnectall() throws ioexception {     connection.disconnect();     dataos.close(); }  private void getcookies() {     sharedpreferences settings = context.getsharedpreferences(prefs_name, 0);     userlogincookie = settings.getstring(user_login, blank);     log.d(log, "cookie: "+userlogincookie);     sessionseedcookie = settings.getstring(sess_seed, blank);     log.d(log, "cookie: "+sessionseedcookie);     sessionuidcookie = settings.getstring(sess_uid, blank);     log.d(log, "cookie: "+sessionuidcookie);     sprefcookie = settings.getstring(s_pref, "spref="+blank);     log.d(log, "cookie: "+sprefcookie); }  private void updatecookies() {     sharedpreferences settings = context.getsharedpreferences(prefs_name, 0);     sharedpreferences.editor editor = settings.edit();      list<httpcookie> cookielist = store.getcookies();     for(int i=0; i<cookielist.size(); i++) {         if(cookielist.get(i).getname().equals(user_login))              editor.putstring(user_login, cookielist.get(i).tostring());         else if(cookielist.get(i).getname().equals(sess_seed))              editor.putstring(sess_seed, cookielist.get(i).tostring());          else if(cookielist.get(i).getname().equals(sess_uid))              editor.putstring(sess_uid, cookielist.get(i).tostring());         else             log.d(log, "found cookie: "+cookielist.get(i).getname());     }     sprefcookie = settings.getstring(s_pref, "spref="+blank);      editor.commit(); //save changes sharedpreferences }         //logins user walkntrade public string login(string email, string password) throws ioexception {     establishconnection(); //instantiate streams , opens connection      string query= "intent=login&password="+password+"&email="+email+"&rememberme=true";     dataos.writebytes(query);     log.d(log, "" + connection.getresponsecode());     updatecookies();      string response = readinputasstring(connection.getinputstream());      log.d(log, "connection status: "+response);      disconnectall();     return response; }  //logs user out of walkntrade public void logout() throws ioexception {      establishconnection();      string query = "intent=logout";     dataos.writebytes(query);     log.d(log, "" + connection.getresponsecode());     updatecookies();      disconnectall(); }  //returns user login status public static boolean isuserloggedin(context _context) {     sharedpreferences settings = _context.getsharedpreferences(prefs_name, 0);     boolean isuserloggedin = settings.getboolean(dataparser.currently_logged_in, false);      return isuserloggedin; }  public string getusername() throws ioexception{     establishconnection();      string query = "intent=getusername";     dataos.writebytes(query);     log.d(log, ""+connection.getresponsecode());     updatecookies();      string response = readinputasstring(connection.getinputstream());      disconnectall();     return response; }  public string getuseravatar() throws ioexception {     establishconnection();      string query = "intent=getavatar";     dataos.writebytes(query);     log.d(log, ""+connection.getresponsecode());     updatecookies();      string response = readinputasstring(connection.getinputstream());      disconnectall();     return response; } 

this code worked fine me prior kitkat 4.4 update -

httpurlconnection urlconnection = (httpurlconnection) url.openconnection();  //handle cookies cookiemanager cookiemanager = new cookiemanager(); cookiehandler.setdefault(cookiemanager); 

it broke after 4.4.2 (at least that's when noticed it), , cookies no longer received. moving cookiemanager , cookiehandler before opening urlconnection fixed again .. bizarre worked before! eg.

//handle cookies cookiemanager cookiemanager = new cookiemanager(); cookiehandler.setdefault(cookiemanager);  httpurlconnection urlconnection = (httpurlconnection) url.openconnection(); 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -