0

Previously,I used HttpClient for a http post request and it was working fine, until I believe the server team made some changes. Then I kept getting javax.net.ssl.SSLPeerUnverifiedException: No peer certificate Exception.

Then, after alot of scratching my head, I tried HttpUrlConnection and it works fine, but still I can't figure out why I got that exception while using HttpClient.

Before code was :

public String postDataAndGetStringResponse( List<NameValuePair> nameValuePairs ) {
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost( link );

        try {

            post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            HttpResponse response = client.execute(post);

            InputStream is = response.getEntity().getContent();

            String result = "";

            if (is != null) {
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(is));

                String l = "";
                while ((l = reader.readLine()) != null) {
                    result += l;
                }

                reader.close();
            }

            is.close();

            return result;
        } catch (Exception e) {
            Logger.printStackTrace(e);
            return ServerUnrechable;
        }


    }

I did check the server using https://www.sslshopper.com and everything is ticked, it would be very helpful if anybody could tell me the cause to this issue.

Nishan Khadka
  • 385
  • 1
  • 2
  • 14

1 Answers1

0

One of the most likely causes is that the server you're trying to use now relies on Server Name Indication.

SNI support was added a to HttpsURLConnection in Android, but not to the Apache HTTP Client bundled (now deprecated/removed). See this related question for details.

Bruno
  • 119,590
  • 31
  • 270
  • 376