获取服务器信任
()
| 386 | * 获取服务器信任 |
| 387 | */ |
| 388 | private static void getTrust() { |
| 389 | try { |
| 390 | HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { |
| 391 | |
| 392 | public boolean verify(String hostname, SSLSession session) { |
| 393 | return true; |
| 394 | } |
| 395 | }); |
| 396 | SSLContext context = SSLContext.getInstance("TLS"); |
| 397 | context.init(null, new X509TrustManager[] { new X509TrustManager() { |
| 398 | |
| 399 | public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {} |
| 400 | |
| 401 | public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {} |
| 402 | |
| 403 | public X509Certificate[] getAcceptedIssuers() { |
| 404 | return new X509Certificate[0]; |
| 405 | } |
| 406 | } }, new SecureRandom()); |
| 407 | HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory()); |
| 408 | } catch (Exception e) { |
| 409 | e.printStackTrace(); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | } |
| 414 |
no outgoing calls
no test coverage detected