微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用JSOUP时SSLPeerUnverifiedException

如何解决使用JSOUP时SSLPeerUnverifiedException

我正在尝试使用JSOUP来解析LAN中的网页,所以我认为我不需要有效的SSL证书,因为它将位于受信任的网络中。我创建了一个扩展AsyncTask的类,以覆盖doInBackground(...)方法,如下所示:

@Override
    protected Void doInBackground(Void... voids) {
        try {
            //Connect to the website
            String url = "https://my.example.webpage/";

            Document document = Jsoup.connect(url).ignoreHttpErrors(true).get();


            String title = document.title();
            Log.d("TAG","WEB TITLE" + title);


        } catch (Exception e) {
            e.printstacktrace();
        }
        return null;
    }

问题是尝试执行特定行时出现SSLPeerUnverifiedException:

文档文档= Jsoup.connect(url).ignoreContentType(true).get();

我的系统输出显示

W/System.err: javax.net.ssl.SSLPeerUnverifiedException: Hostname my.example.webpage not verified:
    certificate: sha1/wJ/Px5KkDt2+bFjaXqgA9QE/Utk=
    DN: CN=xxx.xxx.xxx.cu
    subjectAltNames: [xxx.xxx.xxx.cu]
    at com.android.okhttp.internal.io.RealConnection.connectTls(RealConnection.java:201)
    at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:149)
    at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:112)
    at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184)
    at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126)
etc,etc,etc

我正在使用已经ignoreHttpErrors(true),但仍收到错误。我尝试了带有有效ssl证书的网址,并且一切正常。

我正在尝试解析该页面中的一些文本,如果JSOUP无法解决问题,我将接受任何其他解决方案。

我尝试改用http页面,但是却出现IOException:不允许到my.example.webpage的明文HTTP流量,因此我一直冻结直到获得有效的SSL证书并且我真的不想使用一,尽管不是很好的做法,但也有可能在没有安全性的情况下做到这一点

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。