fix: 校验url时忽略ssl

This commit is contained in:
CaptainB 2021-12-30 12:25:24 +08:00 committed by 刘瑞斌
parent d73ee56f94
commit 4863ed0682
1 changed files with 7 additions and 0 deletions

View File

@ -1,5 +1,8 @@
package io.metersphere.commons.utils; package io.metersphere.commons.utils;
import io.metersphere.ldap.service.CustomSSLSocketFactory;
import javax.net.ssl.HttpsURLConnection;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
@ -9,6 +12,10 @@ public class UrlTestUtils {
try { try {
URL urlObj = new URL(address); URL urlObj = new URL(address);
HttpURLConnection oc = (HttpURLConnection) urlObj.openConnection(); HttpURLConnection oc = (HttpURLConnection) urlObj.openConnection();
if (oc instanceof HttpsURLConnection) {
((HttpsURLConnection) oc).setSSLSocketFactory(new CustomSSLSocketFactory());
((HttpsURLConnection) oc).setHostnameVerifier((hostname, session) -> true);
}
oc.setUseCaches(false); oc.setUseCaches(false);
oc.setConnectTimeout(timeOutMillSeconds); // 设置超时时间 oc.setConnectTimeout(timeOutMillSeconds); // 设置超时时间
int status = oc.getResponseCode();// 请求状态 int status = oc.getResponseCode();// 请求状态