java.io.IOException异常:SSL握手失败:失败的SSL库,通常一个协议错误 [英] java.io.IOException: SSL handshake failure: Failure in SSL library, usually a protocol error

查看:675
本文介绍了java.io.IOException异常:SSL握手失败:失败的SSL库,通常一个协议错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用URL类与来自服务器的特定链接,下载一些内容。

I'm trying to download some content using the URL class with a given link that comes from the server.

我的code下载是:

            URL url = new URL(downloadUrl);
            InputStream stream = url.openStream();
            byte[] content = new byte[stream.available()];
            stream.read(content);
            stream.close();

但是,当运行我得到了以下异常:

But when running I got the following exception:

 java.io.IOException: SSL handshake failure: Failure in SSL library, usually a protocol error
 error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:604 0xaf076228:0x00000000)
     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.nativeconnect(Native Method)
 ...

我所用的链接是这样的:

The link I was using is something like:

https://contentserver.com/d/761/34/215656/5de1a41ea3bc9c81978af95ed19b03286f64d9a3

我知道,如果我进入它的浏览器,它donwload一个文件,我想下载同一个文件throught的Java。

I know if I enter it on browser it donwload an File, I want download the same file throught Java.

感谢

推荐答案

code读取的java从HTTPS URL数据

Code to read data from the https url in java

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.net.*;
import java.security.Security;
import java.util.Properties;

public class UseHttps {

public static void main(String argv[]) {

String fullURL = "https://fortress.wa.gov/lni/bbip/detail.aspx?License=SIBLUCL004C5";
try {

    URL page = new URL(fullURL); // Process the URL far enough to find the right handler
    URLConnection urlc = page.openConnection();
    urlc.setUseCaches(false); // Don't look at possibly cached data
    System.out.println("Content-type = " + urlc.getContentType()); // See what's here
    System.out.println("Content-length = " + urlc.getContentLength()); // See how much of it there is
    // Read it all and print it out
    BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
    String buffer = "";
    while (buffer != null) {
        try {
            System.out.println(buffer);
            buffer = br.readLine();
        }
        catch (IOException ioe) {
            ioe.printStackTrace();
            break;
        }
    }
}
catch (MalformedURLException mue) {
System.out.println(fullURL + " is not a URL that can be resolved");
}
catch (IOException ie) {
ie.printStackTrace();
}
}
}

这篇关于java.io.IOException异常:SSL握手失败:失败的SSL库,通常一个协议错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆