访问此问题后。
我看到了一些答案,最好的显然是 so_mv 的答案。现在看来,他的答案现在已经过时了,因为我已经尝试过所有的导入和确切的代码,但它会产生大量错误。我查看了文档以查看最新的 java 中是否有任何更改,但我似乎无法找到原因。我认为对该问题的更新答案不仅会使我受益,而且会使整个社区受益。
错误:
SecurityCheck.java:28: error: <identifier> expected
sc.init(null, new TrustManager[] { trm }, null);
^
SecurityCheck.java:28: error: illegal start of type
sc.init(null, new TrustManager[] { trm }, null);
^
SecurityCheck.java:28: error: illegal start of type
sc.init(null, new TrustManager[] { trm }, null);
^
SecurityCheck.java:28: error: ')' expected
sc.init(null, new TrustManager[] { trm }, null);
^
SecurityCheck.java:28: error: not a statement
sc.init(null, new TrustManager[] { trm }, null);
^
SecurityCheck.java:28: error: ';' expected
sc.init(null, new TrustManager[] { trm }, null);
^
SecurityCheck.java:28: error: illegal start of type
sc.init(null, new TrustManager[] { trm }, null);
^
SecurityCheck.java:28: error: ';' expected
sc.init(null, new TrustManager[] { trm }, null);
^
SecurityCheck.java:28: error: illegal start of type
sc.init(null, new TrustManager[] { trm }, null);
^
SecurityCheck.java:28: error: <identifier> expected
sc.init(null, new TrustManager[] { trm }, null);
^
SecurityCheck.java:28: error: ';' expected
sc.init(null, new TrustManager[] { trm }, null);
^
SecurityCheck.java:29: error: illegal start of type
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
^
SecurityCheck.java:29: error: <identifier> expected
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
^
SecurityCheck.java:29: error: ';' expected
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
^
SecurityCheck.java:29: error: illegal start of type
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
^
SecurityCheck.java:29: error: <identifier> expected
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
^
SecurityCheck.java:29: error: ';' expected
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());