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 6869009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:30:19+00:00 2026-05-27T03:30:19+00:00

I have an DefaultHttpClient that don’t check for certificates that I use at both

  • 0

I have an DefaultHttpClient that don’t check for certificates that I use at both activity:

public function clientWithoutCertificateCheck() {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    try{
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
        httpClient = new DefaultHttpClient(ccm, params);
    } catch (Exception e) { }

    return httpClient;
}

and it does login at a page inside this same activity.

After start the other activity I save it’s cookies:

CookieSyncManager.createInstance(this);
List<Cookie> cookies = httpClient.getCookieStore().getCookies();
for(Cookie cookie : cookies)
{
    String cookieString = cookie.getName() + "=" + cookie.getValue() + "; domain=" + cookie.getDomain();                        
    CookieManager.getInstance().setCookie(cookie.getDomain(), cookieString);  
}

Then I’m trying to get the same httpClient at another activity.

DefaultHttpClient httpClient = clientWithoutCertificateCheck();
String url = "https://academicos.unilasalle.edu.br/";
String[] keyValueSets = CookieManager.getInstance().getCookie(url).split(";");
for(String cookie : keyValueSets)
{
    String[] keyValue = cookie.split("=");
    String key = keyValue[0];
    String value = "";
    if(keyValue.length>1) value = keyValue[1];
    httpClient.getCookieStore().addCookie(new BasicClientCookie(key, value));
}

and for some reason he isn’t logged in anymore.

Can someone help me solve this?

  • 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-27T03:30:19+00:00Added an answer on May 27, 2026 at 3:30 am

    According to your code, obviously by calling clientWithoutCertificateCheck() always return a newly created httpClient, not the same one from previous activity. So on the server side, it may think these are different incoming connection and associate with different sessions/cookies.

    Activity’s life cycle is quite transitory, usually it gets created/destroyed many times during application running time. From my point of view, it is not reasonable to bind httpClient to Activity.
    If you want to retain/use single httpClient instance cross avtivities, consider using service, implement/centralize your http related stuff into your HttpService, and start/bind service for all activities that need use http service. hope that help.

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

Sidebar

Related Questions

I have a method that I need to run when the activity starts. I've
I have created a new class called Get_WebPage1 and init I have extends that
i have a function that fill up my SQLite DB with entries of a
I'd like to programmatically access a site that requires Client certificates, which I have
I have a login form in Android that I want to use to send
I have used the following code on my client side (Android emulator). HttpClient client=new
I have a problem that I think it may relate to the HttpClient. I
I have some code: public class Foo { private HttpClient httpClient; public Foo() {
I have a piece of code using the DefaultHttpClient and it makes a post
So I have a API issue. So i am creating a class that utilizes

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.