IOException:javax.net.ssl.SSLHandshakeException:SSL握手已中止:ssl = 0xafdb8e00:系统调用期间的I / O错误,同级连接重置

时间:2016-02-17 17:20:46

标签: java android ssl httpsurlconnection

嘿,我有一个http请求,今天工作正常我收到了错误

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

这就是我如何完成正常工作的请求

   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();
    }

有任何帮助吗? 此致

1 个答案:

答案 0 :(得分:-2)

当互联网连接速度缓慢或您的应用无法连接到服务器时,会发生此异常。