javax.net.ssl.SSLHandshakeException:连接被同级1关闭

时间:2018-07-28 11:01:19

标签: android httpurlconnection sslhandshakeexception

有人可以帮助我,为什么我会收到此错误?我想下载一些json内容。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    DownloadTask task = new DownloadTask();
    try {
        task.execute("https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty");
    } catch (Exception e) {
        e.printStackTrace();
    }


}

public  class DownloadTask extends AsyncTask<String, Void, String>{

    @Override
    protected String doInBackground(String... params) {
        String result = "";
        URL url;
        HttpURLConnection connection = null;



        try {
            url = new URL(params[0]);
            connection = (HttpURLConnection) url.openConnection();
            connection.connect();
            InputStream in = connection.getInputStream();
            InputStreamReader reader = new InputStreamReader(in);
            int data = reader.read();

            while (data != -1){
                char current = (char) data;
                result += current;
                data = reader.read();
            }

            Log.i("result", result);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}

错误:

07-28 10:15:29.522 3733-3749/com.example.samin.newsreader W/System.err: javax.net.ssl.SSLHandshakeException: Connection closed by peer
07-28 10:15:29.522 3733-3749/com.example.samin.newsreader W/System.err:     at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
07-28 10:15:29.522 3733-3749/com.example.samin.newsreader W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:357)
07-28 10:15:29.522 3733-3749/com.example.samin.newsreader W/System.err:     at com.android.okhttp.Connection.connectTls(Connection.java:235)
07-28 10:15:29.522 3733-3749/com.example.samin.newsreader W/System.err:     at com.android.okhttp.Connection.connectSocket(Connection.java:199)
07-28 10:15:29.522 3733-3749/com.example.samin.newsreader W/System.err:     at com.android.okhttp.Connection.connect(Connection.java:172)
07-28 10:15:29.522 3733-3749/com.example.samin.newsreader W/System.err:     at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
07-28 10:15:29.523 3733-3749/com.example.samin.newsreader W/System.err:     at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
07-28 10:15:29.523 3733-3749/com.example.samin.newsreader W/System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
07-28 10:15:29.523 3733-3749/com.example.samin.newsreader W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
07-28 10:15:29.523 3733-3749/com.example.samin.newsreader W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
07-28 10:15:29.523 3733-3749/com.example.samin.newsreader W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
07-28 10:15:29.523 3733-3749/com.example.samin.newsreader W/System.err:     at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
07-28 10:15:29.523 3733-3749/com.example.samin.newsreader W/System.err:     at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java)

0 个答案:

没有答案