我正在尝试在我的网页浏览中打开Https SelfSigned证书网站,但我遇到问题,因为我收到SSLConnection错误。 以下是我的代码。
URL url;
String response = "";
try {
url = new URL(requestURL);
HttpURLConnection http;
if (url.getProtocol().toLowerCase().equals("https")) {
// conn = (HttpURLConnection) url.openConnection();
// trustAllHosts();
HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
// https.setHostnameVerifier(DO_NOT_VERIFY);
http = https;
} else {
http = (HttpURLConnection) url.openConnection();
}
http.setReadTimeout(60 * 1000);
http.setConnectTimeout(60 * 1000);
http.setRequestMethod("POST");
http.setDoInput(true);
http.setDoOutput(true);
OutputStream os = http.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(getPostDataString(postDataParams));
writer.flush();
writer.close();
os.close();
int responseCode = http.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
String line;
BufferedReader br = new BufferedReader(new InputStreamReader(http.getInputStream()));
while ((line = br.readLine()) != null) {
response += line;
}
} else {
response = "";
}
Logger.d("Response Result", "performPostCall: " + response);
} catch (Exception e) {
e.printStackTrace();
}
如何在WebView中打开它?我试过了
@Override
public void onReceivedSslError(WebView view, @NonNull final SslErrorHandler handler,
SslError error) {
handler.proceed();
}
但它不起作用。 敬请任何帮助。