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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:49:19+00:00 2026-06-03T12:49:19+00:00

Possible Duplicate: javax.net.ssl.SSLException: Not trusted server certificate I am trying to connect to server

  • 0

Possible Duplicate:
javax.net.ssl.SSLException: Not trusted server certificate

I am trying to connect to server using “https” scheme with .bks keystore but i am unable to connect due to this issue.

Can any one tell me what’s the reason for this and how to solve this.

Here is my code

public String httpRestGetCallwithCertificate(String url, String payLoad) {
        String result = null;
        DefaultHttpClient httpClient = null;
        KeyStore trustStore = null;
        try {
            httpClient = new DefaultHttpClient(getHttpParams());
            HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

            HttpHost targetHost = new HttpHost("hostname","portno","https");
            httpClient.getCredentialsProvider().setCredentials(
                    new AuthScope(targetHost.getHostName(), targetHost.getPort()),
                    new UsernamePasswordCredentials("username","password"));
            trustStore  = KeyStore.getInstance(KeyStore.getDefaultType());

            InputStream instream = mContext.getResources().openRawResource(R.raw.truststore);
            try {
                trustStore.load(instream, "password".toCharArray());

            } finally {
                try { instream.close(); } catch (Exception ignore) {}
            }
            SchemeRegistry registry = new SchemeRegistry();
            SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
            socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
            Scheme sch = new Scheme("https", socketFactory, 443);
            registry.register(sch);
            HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
            httpClient.getConnectionManager().getSchemeRegistry().register(sch);
            HttpGet httpget = new HttpGet(url);
            HttpResponse response = httpClient.execute(httpget);
            if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                return "success"
            }
        } catch (UnsupportedEncodingException exception) {
            exception.printStackTrace();
        } catch (ConnectTimeoutException exception) {
            Log.e(TAG, "Network connetcion is not available");
            exception.printStackTrace();
        }catch(SocketTimeoutException exception){
            Log.e(TAG, "Socket timed out.");
            exception.printStackTrace();
        } catch (IOException exception) {
            Log.v("IO Exception", exception.toString());
            exception.printStackTrace();
        } catch (KeyStoreException e) {
            e.printStackTrace();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnrecoverableKeyException e) {
            e.printStackTrace();
        } catch (CertificateException e) {
            e.printStackTrace();
        } finally {
            if (httpClient.getConnectionManager() != null) {
                httpClient.getConnectionManager().shutdown();
            }
            httpPost = null;
        }
        return "fail";
    }

and below is my stack trace

03-06 16:53:50.460: W/System.err(1655): javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
03-06 16:53:50.460: W/System.err(1655):     at org.apache.harmony.xnet.provider.jsse.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:137)
03-06 16:53:50.470: W/System.err(1655):     at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:93)
03-06 16:53:50.470: W/System.err(1655):     at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)
03-06 16:53:50.470: W/System.err(1655):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
03-06 16:53:50.470: W/System.err(1655):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
03-06 16:53:50.470: W/System.err(1655):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
03-06 16:53:50.470: W/System.err(1655):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
03-06 16:53:50.480: W/System.err(1655):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
03-06 16:53:50.480: W/System.err(1655):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
03-06 16:53:50.480: W/System.err(1655):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)

And i am getting the exception while executing below line

HttpResponse response = httpClient.execute(httpget);

  • 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-06-03T12:49:20+00:00Added an answer on June 3, 2026 at 12:49 pm

    As Danial said while answering below question,
    we should create a custom class from org.apache.http.conn.ssl.SSLSocketFactory, not the one org.apache.http.conn.ssl.SSLSocketFactory itself

    Trusting all certificates using HttpClient over HTTPS

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

Sidebar

Related Questions

Possible Duplicate: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25; I am
Possible Duplicate: Why are Exceptions not Checked in .NET? Coming from Eclipse/Java, I noticed
Possible Duplicate: Java sockets - java.net.ConnectException: Connection refused: connect I've created a simple chat
Possible Duplicate: Why are Exceptions not Checked in .NET? Java makes distinction of checked
Possible Duplicate: Print preview ZPL II commands using .NET WinForm before sending it to
Possible Duplicate: why import javax.swing.* why not import java.swing.* This may seem as a
I'm trying to duplicate something you can do in .Net but not having much
Possible Duplicate: Is shifting bits faster than multiplying and dividing in Java? .NET? To
Possible Duplicate: Traditional ASP .NET vs MVC I am new to .net world coming
Possible Duplicate: Java Class.cast() vs. cast operator I am unsuccessfully trying to find out

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.