Django session id on android -
we have django framework setup , login in django working. need session-id on android , not sure how can this. if make http post android need session id django can use future post , requests user.
to achieve need maintain session. , maintain session there 2 posibilities
1) use single defaulthttpclient request.
this approach not work if want call multiple request simultaneously.
2) sync common cookies among multiple defaulthttpclient connections.
public static list<cookie> cookies;
read session cookies after login.
httpresponse wsresponse = httpclient.execute(httppost); try { cookies = httpclient.getcookiestore().getcookies(); sync(); } catch (exception e) { } public static defaulthttpclient gethttpclient() { httpparams httpparameters = new basichttpparams(); httpconnectionparams.setconnectiontimeout(httpparameters, timeout); httpconnectionparams.setsotimeout(httpparameters, timeout); defaulthttpclient httpclient = new defaulthttpclient(httpparameters); if (cookies != null) { int size = cookies.size(); (int = 0; < size; i++) { httpclient.getcookiestore().addcookie(cookies.get(i)); } } return httpclient; }
update:
public void sync() { if (cookies != null) { cookiemanager cookiemanager = cookiemanager.getinstance(); cookiemanager.setacceptcookie(true); (cookie cookie : cookies) { cookie sessioninfo = cookie; string cookiestring = sessioninfo.getname() + "=" + sessioninfo.getvalue() + "; domain=" + sessioninfo.getdomain(); cookiemanager.setcookie("http://yourdomain.com", cookiestring); cookiesyncmanager.getinstance().sync(); } } }
this sync()
method use manage session httpclient , webview/browser.that if want perform log-in native application , want specific operation on webview required log-in method manage common session between app , webview/browser.
Comments
Post a Comment