1. 程式人生 > >xUtils3 Https請求報錯:javax.net.ssl.SSLPeerUnverifiedException: Hostname ***.****.**not verified,跳過證書檢測

xUtils3 Https請求報錯:javax.net.ssl.SSLPeerUnverifiedException: Hostname ***.****.**not verified,跳過證書檢測

使用xUtils3傳送https請求報錯javax.net.ssl.SSLPeerUnverifiedException: Hostname ***.****.**not verified。

我想不驗證證書直接進行訪問(和http一樣了)。

解決過程: 
   剛開始設定 (requestParams是引數物件)

    /** 判斷https證書是否成功驗證 */
        SSLContext sslContext = getSSLContext(MyApp.mContext);
        if (null == sslContext) {
            Utils.LogUtils("Error:Can't Get SSLContext!");
            return;
        }
        requestParams.setSslSocketFactory(sslContext.getSocketFactory()); //繫結SSL證書(https請求)


    /**
     * 獲取Https的證書
     *
     * @param context Activity(fragment)的上下文
     * @return SSL的上下文物件
     */
    private static SSLContext s_sSLContext = null;


    private static SSLContext getSSLContext(Context context) {
        try {
            s_sSLContext = SSLContext.getInstance("TLS");
            //信任所有證書 (官方不推薦使用)
            s_sSLContext.init(null, new TrustManager[]{new X509TrustManager() {


                @Override
                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }


                @Override
                public void checkServerTrusted(X509Certificate[] arg0, String arg1)
                        throws CertificateException {


                }


                @Override
                public void checkClientTrusted(X509Certificate[] arg0, String arg1)
                        throws CertificateException {


                }
            }}, new SecureRandom());
            return s_sSLContext;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

結果還是報錯,網上搜了一下:


在設定信任所有證書前要執行setDefaultHostnameVerifier方法,可是Xutils3裡面的requestParams並沒有這個方法。怎麼辦,繼續找。。。。

終於發現:

在初始化Xutitls時:

x.Ext.setDefaultHostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        });

問題解決。

相關推薦

xUtils3 Https請求javax.net.ssl.SSLPeerUnverifiedException: Hostname ***.****.**not verified證書檢測

使用xUtils3傳送https請求報錯javax.net.ssl.SSLPeerUnverifiedException: Hostname ***.****.**not verified。 我想不驗證證書直接進行訪問(和http一樣了)。 解決過程:    剛開始設定 (

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated 問題解決

最近線下除錯銀聯支付時報錯: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SS

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

Hello,小夥伴好久不見!今天在聯調介面時,遇到一個錯誤,糾結了好久才解決.雖然是粗心引起的,但是也大概明白了引起這個錯誤的來龍去脈,現在整理一下,分享給大家,希望大家在遇到這個類似問題了,不會太無助; 前言 我們來看下問題發生的大背景;這次我們聯

HttpClient的”javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated”異常

在開發https應用時,你的測試伺服器常常沒有一個(有效的)SSL證書。在你的客戶端連線測試伺服器時,如下的異常會被丟擲:”javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated”。 1. 程

避免HttpClient的”javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated”異常

在開發https應用時,你的測試伺服器常常沒有一個(有效的)SSL證書。在你的客戶端連線測試伺服器時,如下的異常會被丟擲:”javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated”。 解決方案:修改建

https請求解決javax.net.ssl.SSLException: Not trusted ...

通過https協議請求資料報錯了一下錯誤:javax.net.ssl.SSLException: Not trusted server certificate exception.在國外論壇上找了個解決的方案和大家分享。      我們需要自定義一個繼承org.apache.http.conn.ssl.SS

Https協議com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl解決方法

toc 使用 地址 bae aaaaa line 點擊 pro details 旭日Follow_24 的CSDN 博客 ,全文地址請點擊: https://blog.csdn.net/xuri24/article/details/82220333 所用應用服務器:JBos

解決java.net.BindException: 無法指定被請求的地址

今天在linux虛擬機器上裝了tomcat,但是一直啟動不了,檢視日誌,主要報錯如下: 嚴重: StandardServer.await: create[localhost:8005]: java.net.BindException: 無法指定被請求的地址 at java.n

git https 請求 504

AS ash 檢查 沒有 系統 http ID 去掉 ubun git https 請求報錯 504 原因可能是因為設置了代理,ubuntu/deepin 系統可以檢查 /etc/profile ~/.bashrc 內有沒有設置 https 的代理。 有的話,去掉就可

java.net.bindexception: address already in use: jvm_bind:8080

lips RoCE ava ESS build 命令 ips 顯示 exception 原因:8080端口被占用 這說明80端口(該端口是Tomcat的監聽端口)已經被其他程序占用,先用命令提示符 " netstat -ano " 命令顯示端口狀態,再在結果中找到端口,然

java.net.bindexception: address already in use: jvm_bind

exceptio exc 原因 報錯 pan use ddr net exce 原因:8080端口被占用 報錯:java.net.bindexception: address already in use: jvm_bind

retrofit請求Expected a string but was BEGIN_OBJECT at line 1 column 2 path $

Expected a string but was BEGIN_OBJECT at line 1 column 2 path $ 這樣的錯,意思就是我想幫你解析成String而你返回的資料是一個物件,解析不了 需要把返回的物件String 給成JsonObject就可以了 如:C

Springboot訪問jsp頁面javax.servlet.jsp.JspFactory.getJspApplicationContext

搭建springboot專案時,專案啟動成功,訪問jsp頁面跳轉時報錯,錯誤如下: java.lang.NoSuchMethodError: javax.servlet.jsp.JspFactory.getJspApplicationContext(Ljavax/servl

【我的Android進階之旅】使用Retrofit進行Post請求 @Field parameters can only be used with form encoding.

一、問題描述 今天隨手寫一個post請求的時候,報錯了,如下所示: 09-28 11:11:28.155 10547-10547/com.xtc.watch E/Fatal: {CrashHandler.saveAndPrintLog-58} jav

RK 6.0 專案編譯android.net.wif... cannot be found in source files,imported jack lib or classpatch

自己寫的原始碼,放到7.1和8.1上面編譯都沒有問題,在6.0上編譯的時候報android.net.wif… cannot be found in source files,imported jack lib or classpatch 看到這個錯誤時有點蒙,猜測是和libs或api有關係

resin https 請求解決

問題: 遊戲支付完後,通知服務端,服務端要去蘋果伺服器驗證訂單是否合法。採用的是封裝好的HttpClient 工具。 在與客戶端聯調時,驗證訂單這一步報錯 javax.net.ssl.SSLHandshakeException: Failed to

基於SpringCloud+不同主機上的微服務相互呼叫java.net.UnknownHostException:主機名

專案背景:採用Spring Cloud+IEDA+Maven搭建了由多個微服務組成的專案,部署上線是用的是Docker容器技術。 問題描述:部署上線過程中,各個微服務都正常啟動,而且都註冊到了eureka註冊中心,但是相互呼叫時報java.net.Unknown

解決asynchttpclient https請求hostname in certificate didn't match:

錯誤: javax.NET.ssl.SSLException:hostname in certificate didn’t match:<..*.com> != <.**.com&g

tomcat啟動java.net.BindException: Permission denied :80

1,啟動報錯顯示 [org.springframework.web.servlet.DispatcherServlet]FrameworkServlet 'springMvc': initialization completed in 382 ms Jun

jetty 啟動 java.net.BindException: Address already in use

開始新的IDE和容器之旅,IDEA + Jetty,啟動jetty的時候報錯: java.net.BindException: Address already in use: 原因:埠被佔用。 查看了一下,Apache和Maven控制檯開著,於是先關閉Apache,再試,還