【问题标题】:ssl.SSLHandshakeException occurs when try to read xml from URL尝试从 URL 读取 xml 时发生 ssl.SSLHandshakeException
【发布时间】:2013-06-01 00:59:38
【问题描述】:

尝试从 URL 读取 XML 时出现 SSLHandshakeException。 错误发生在这一行: 文档 doc = db.parse(new InputSource(url.openStream()));

    protected LinearLayout doInBackground(String... string) {
        LinearLayout layout = new LinearLayout(DevicesActivity.this);
        layout.setOrientation(1);
        /** Create a new textview array to display the results */ 
        TextView device[];

        try {
            URL url = new URL();
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse(new InputSource(url.openStream())); 
            doc.getDocumentElement().normalize();

日志:

05-30 15:18:21.742: I/Choreographer(12300): Skipped 59 frames!  The application may be doing too much work on its main thread.
05-30 15:18:22.305: I/ActivityManager(290): Displayed com.example.wip/.DevicesActivity: +2s340ms
05-30 15:18:23.992: I/System.out(12300): XML Pasing Excpetion = javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

当我尝试查看 URL 的页面信息时,我也从 Chrome 收到了这条消息

the identity of this website has not been verified.• server's certificate is not trusted

这是网站服务器的问题吗?我可以自己解决吗?

【问题讨论】:

    标签: java android


    【解决方案1】:

    问题出在服务器端。它使用了错误的证书。 (根据火狐的说法,服务器不包括票证发行者链。这甚至不是自签名证书。它只是配置错误。)

    我可以自己解决吗?

    您需要将服务器的证书作为受信任的证书添加到手机的密钥库中。我不确定这是个好主意。

    【讨论】:

    • 谢谢。我怎样才能做到这一点?我想试试看能不能得到 XML。
    • 如果你想要的只是 XML,然后使用 Web 浏览器下载它,告诉浏览器无论如何都要使用错误的证书。但请注意,服务器需要用户名和密码。
    猜你喜欢
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多