java - (Android) Cookie problems in HttpClient, URL and HttpURLConnection -



java - (Android) Cookie problems in HttpClient, URL and HttpURLConnection -

i going add together captcha validation in registration form in android apps. found server gives signal me there no session. finally, found cookie of application stored nothing.

i cannot register business relationship though validation correct. sure there no problem in php server because have tested in browser.

i have made 3 types of connection test cookie issue.

1) httpclient

httpresponse response = httpclient.execute(httppost);

2) url

bitmap bitmap = bitmapfactory.decodestream((inputstream)new url("http://www.example.com/abc.png").getcontent());

3) httpurlconnection

private void send_post(httpurlconnection connection,string variable_set) throws exception { connection.setdooutput(true); connection.setdoinput(true); connection.setinstancefollowredirects(false); connection.setrequestmethod("post"); connection.setrequestproperty("content-type", "application/x-www-form-urlencoded"); connection.setrequestproperty("charset", "utf-8"); connection.setrequestproperty("content-length", "" + integer.tostring(variable_set.getbytes().length)); connection.setusecaches(false); dataoutputstream wr = new dataoutputstream(connection.getoutputstream()); wr.writebytes(variable_set); wr.flush(); wr.close(); }

also, add together code setup cookie.

cookiemanager cookiemanager = new cookiemanager(); cookiehandler.setdefault(cookiemanager);

unfortunately, httpurlconnection successes utilize cookie , server shows there session variables. yet, application using url , httpclient.

could tell me how enable cookie in httpclient , url?

here sample code set jsessionid (of apache tomcat server) cookie in android. hope give thought doing similar process in php:

defaulthttpclient httpclient = new defaulthttpclient(); httpclient.setcookiestore(new basiccookiestore()); basicclientcookie cookie = new basicclientcookie("jsessionid<<or variable name>>", <<actual value>>); cookie.setdomain(<<set domain name here>>); cookie.setpath("/"); httpclient.getcookiestore().addcookie(cookie); httpentity httpentity = null; httpresponse httpresponse = null; // checking http request method type if (method == post) { httppost httppost = new httppost(url); httppost.setheader("accept", "application/json"); //use text/plain if response if http response plain text httppost.setheader("content-type", "application/x-www-form-urlencoded"); if (formdata != null) { httppost.setentity(new urlencodedformentity(formdata, http.utf_8)); } httpresponse = httpclient.execute(httppost); } else if (method == get) { if (formdata != null) { string paramstring = urlencodedutils.format(formdata, "utf-8"); url += "?" + paramstring; } httpget httpget = new httpget(url); httpresponse = httpclient.execute(httpget); } status_code = httpresponse.getstatusline().getstatuscode(); httpentity = httpresponse.getentity(); log.i("status code after login", "> >status code > >" + status_code + "> >url > >"+url); if(status_code==200) response = entityutils.tostring(httpentity); else response="fail"; <<response contain final http response>>

java php android cookies captcha

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -