1

Hey i have a http request and it was working fine today i have received an error

 IOException : javax.net.ssl.SSLHandshakeException: SSL handshake aborted: ssl=0xafdb8e00: I/O error during system call, Connection reset by peer

this is how i do the request which was working perfectly

   try {
        Url = new URL(url);
        urlConnection = (HttpURLConnection) Url.openConnection();
        urlConnection.setRequestMethod("POST");
        urlConnection.setUseCaches(false);
        urlConnection.setConnectTimeout(30000);
        urlConnection.setReadTimeout(30000);
        urlConnection.setRequestProperty("Content-Type", "text/xml");
        urlConnection.setRequestProperty("Host", "host");


        String body = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> \n" +
                " <soap:Body> \n" +
              xml data
                " </soap:Body> \n" +
                " </soap:Envelope>";

        System.out.println("the body is " + body);

        byte[] outputInBytes = body.getBytes("UTF-8");

        OutputStream os = urlConnection.getOutputStream();

        os.write(outputInBytes);

        //System.out.println("Message = " + urlConnection.getResponseMessage());

        System.out.println(" * 3");

        //urlConnection.connect();

        if (urlConnection.getResponseCode() == 200) {
            InputStream in = new BufferedInputStream(urlConnection.getInputStream());
            result = IOUtils.toString(in, "UTF-8");
            System.out.println("Salik Success is" + result);

            os.close();

            return result;
        } else {
            InputStream in = new BufferedInputStream(urlConnection.getErrorStream());
            result = IOUtils.toString(in, "UTF-8");
            System.out.println("Failure is" + result);


            os.close();

            return null;
        }


    } catch (MalformedURLException e) {
        //e.printStackTrace();
        result = "error";
        System.out.println("MalformedURLException = " + e.toString());
    } catch (IOException e) {
        //e.printStackTrace();
        result = "error";
        System.out.println("IOException" + e.toString());
    } finally {
        urlConnection.disconnect();
    }

Any help ? Regards

Antwan
  • 3,837
  • 9
  • 41
  • 62
  • Possible duplicate of [javax.net.ssl.SSLException: SSL handshake aborted Connection reset by peer while calling webservice Android](https://stackoverflow.com/questions/20741405/javax-net-ssl-sslexception-ssl-handshake-aborted-connection-reset-by-peer-while) – User Sep 13 '18 at 00:32
  • Please refer to these contents: http://stackoverflow.com/questions/12885247/why-is-httpurlconnection-throwing-an-sslexception-while-on-a-mobile-data-connect http://stackoverflow.com/questions/20741405/javax-net-ssl-sslexception-ssl-handshake-aborted-connection-reset-by-peer-while – Daniel X Oct 30 '18 at 13:02

1 Answers1

-3

This exception happens when internet connection is slow or your app cannot connect to the server..

Matt
  • 74,352
  • 26
  • 153
  • 180
App Crazy
  • 46
  • 4