Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6191383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:45:14+00:00 2026-05-24T02:45:14+00:00

This method is used to consume a web service which I also control. The

  • 0

This method is used to consume a web service which I also control. The web service sets cookies to keep the user logged in.

This all works fine through a browser. i.e. I can call the login url, it will cookie my browser, and subsequent access to the web service recognizes my cookies.

In android, I can get a successful return on my login, but the cookies do not seem to be setting.

You can see where this code prints the cookie data to the output. It prints the cookie when it hits the login script, but for subsequent calls to this function, it does not recognize the cookie anymore.

Here’s the code I’m using, I started from an example someone else posted:

private JSONObject getResponse(String func, List<NameValuePair> args) throws Exception {

    HttpClient httpclient = new DefaultHttpClient();
    try {
        // Create a local instance of cookie store
        CookieStore cookieStore = new BasicCookieStore();

        // Create local HTTP context
        HttpContext localContext = new BasicHttpContext();
        // Bind custom cookie store to the local context
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

        HttpPost put= new HttpPost("http://example.com/api/" + func);
        if (args != null) {
            put.setEntity(new UrlEncodedFormEntity(args));
        }

        System.out.println("executing request " + put.getURI());

        // Pass local context as a parameter
        HttpResponse response = httpclient.execute(put, localContext);
        HttpEntity entity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (entity != null) {
            System.out.println("Response content length: " + entity.getContentLength());
        }
        List<Cookie> cookies = cookieStore.getCookies();
        for (int i = 0; i < cookies.size(); i++) {
            System.out.println("Local cookie: " + cookies.get(i));
        }

        // Consume response content
        //EntityUtils.consume(entity);
        System.out.println("----------------------------------------");

        InputStream instream = entity.getContent();
        String result = convertStreamToString(instream);
        instream.close();
        entity.consumeContent();

        System.out.println("JSON Output: " + result);

        return new JSONObject(result);

    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:45:15+00:00Added an answer on May 24, 2026 at 2:45 am

    That might be because your HttpClient and CookieStore are local to getResponse. Try making them global so they persist onto subsequent calls.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

WCF-service is hosted by ASP.NET web-site. ASP.NET Membership is not used in web-site. User
I have a web-service running on Windows Azure which returns JSON that I consume
I used the method $(#dvTheatres a).hover(function (){ $(this).css(text-decoration, underline); },function(){ $(this).css(text-decoration, none); } );
I have this method Verify_X which is called during databind for a listbox selected
I'm building a .NET component that will call an external web service. I used
Hey, I am trying to return a user defined class from a web method.
i used this method to handle shake event on my app , but i
I'm currently creating a permissions table which replicated the 777 method used in linux.
I have this method on a webpart: private IFilterData _filterData = null; [ConnectionConsumer(Filter Data
Every time I call this method my NSMutableData is leaking and I cannot figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.