0

I'm coding a login system which will keep the user permanently logged on (until username or password is incorrect) but I'm having an issue with cookie storage. What I want to do is have the cookies store in local storage (probably shared preference). Though I have no idea where to start. This is my main HTTP Post function.

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);
    try {
        // Add your data
        httppost.setHeader("X-Requested-With", "XMLHttpRequest");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();

        StringBuffer sb = new StringBuffer();
        BufferedReader rd = new BufferedReader(new InputStreamReader(entity.getContent()));
        String line;
        while ((line = rd.readLine()) != null) {
            sb.append(line);
        }
        rd.close();
        return sb.toString();
    } catch (Exception e) {
        //TODO: WIP
        e.printStackTrace();
    }

I want to set the cookies first (of course if there are any) then I would like to resave them after the httppost has executed. Where can I go about doing this?

Edit there is about 4 cookies that are saved.

arberb
  • 960
  • 3
  • 14
  • 25

1 Answers1

1

This should help you get started:

http://docs.oracle.com/javase/tutorial/networking/cookies/definition.html

Check out this post as well:

https://stackoverflow.com/a/3587332/2495131

Community
  • 1
  • 1
JustSoAmazing
  • 747
  • 4
  • 8
  • I ended up ripping the persistentcookiestore off LoopJ's async http. But thanks for the help :) – arberb Feb 17 '14 at 19:20