Recently done projects on the phone side login HTTP request and WebView record login to get cookie information, can view cookie information.
HTTP request for cookie information:
Public Staticstring Request (String Httpurl, string params, context context) {BufferedReader Reader=NULL; String result=NULL; String Httpurl= "Http://xwwscs.com"; StringBuffer SBF=NewStringBuffer (); Try{URL URL=NewURL (Httpurl + "/app.php")); HttpURLConnection Connection=(HttpURLConnection) url.openconnection (); Connection.setrequestmethod ("POST"); Connection.setrequestproperty ("Cookie", Cookieutil.getparam (context). ToString ()); Connection.setconnecttimeout (3000); //whether to enter parametersConnection.setdooutput (true); byte[] Bypes =params.tostring (). GetBytes (); Connection.getoutputstream (). write (bypes);//Input ParametersConnection.connect (); InputStream is=Connection.getinputstream (); Reader=NewBufferedReader (NewInputStreamReader (IS, "UTF-8")); String Strread=NULL; while((Strread = Reader.readline ())! =NULL) {sbf.append (strread); Sbf.append ("\ r \ n"); } reader.close (); Map<string, list<string>> cookie_map =Connection.getheaderfields (); List<String> cookies = cookie_map.get ("Set-cookie"); if(NULL! = Cookies && 0 <cookies.size ()) {String s= ""; for(String cookie:cookies) {if(S.isempty ()) {s=cookies; } Else{s+= ";" +cookies; }} log.i ("Cookie", s); } result=sbf.tostring (); } Catch(Exception e) {result= "Error"; E.printstacktrace (); } returnresult; }}
WebView loading web page for cookie
Webview.setwebviewclient (Newwebviewclient () {@Override Public Booleanshouldoverrideurlloading (WebView view, String URL) {//TODO auto-generated Method Stub return Super. shouldoverrideurlloading (view, URL); } @Override Public voidonpagefinished (WebView view, String URL) {Cookiemanager cookiemanager=cookiemanager.getinstance (); String cookiestr=cookiemanager.getcookie (URL); if(cookiestr!=NULL) {log.i ("Cookie", cookiestr); } Super. onpagefinished (view, URL); } });
How HTTP loading in Android gets cookies and WebView loading pages how to get cookies