androidsslexception

Unable to make a https request from android error - Connection closed by peer


I am trying to an https request from android to an api endpoint 'https://api_chamakah.ivilleinc.com/'. However regardless of what options I try I get "Connection close by peer", requests from post man and the browser work fine.

String webUrl = EndPointMethods.BASE_URL  + EndPointMethods.CATEGORIES;
                URL url = new URL(webUrl);
                HttpsURLConnection urlConnection = (HttpsURLConnection)url.openConnection();
                try {
                    urlConnection.setSSLSocketFactory(new SSLSocketFactoryExtended());
                } catch (NoSuchAlgorithmException e) {  e.printStackTrace();  }
                catch (KeyManagementException e) { e.printStackTrace();}

                urlConnection.setRequestMethod("GET");
                BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
                String inputLine;
                StringBuffer response = new StringBuffer();

                while ((inputLine = in.readLine()) != null) {
                    response.append(inputLine);
                }
                in.close();

Solution

  • After using this tool, I believe the underscore in the hostname is the issue. See this thread which confirms your work-around for your JDK and may explain why other tools aren't impacted.