|
4 | 4 | import org.javawebstack.httpclient.interceptor.ResponseTransformer; |
5 | 5 | import org.javawebstack.querystring.QueryString; |
6 | 6 |
|
| 7 | +import javax.net.ssl.*; |
7 | 8 | import java.io.ByteArrayOutputStream; |
8 | 9 | import java.io.IOException; |
9 | 10 | import java.io.InputStream; |
10 | 11 | import java.io.OutputStream; |
11 | | -import java.net.HttpURLConnection; |
12 | | -import java.net.URL; |
| 12 | +import java.net.*; |
13 | 13 | import java.nio.charset.StandardCharsets; |
| 14 | +import java.security.cert.X509Certificate; |
14 | 15 | import java.util.Base64; |
15 | 16 | import java.util.HashMap; |
16 | 17 | import java.util.Map; |
@@ -162,6 +163,24 @@ public HTTPRequest execute(){ |
162 | 163 | try{ |
163 | 164 | URL theUrl = new URL(client.getBaseUrl() + ((path.startsWith("/") || path.startsWith("http://") || path.startsWith("https://")) ? "" : "/") + path + (query.size() > 0 ? "?" + query.toString() : "")); |
164 | 165 | conn = (HttpURLConnection) theUrl.openConnection(); |
| 166 | + if(!client.isSSLVerification() && conn instanceof HttpsURLConnection){ |
| 167 | + HttpsURLConnection httpsConn = (HttpsURLConnection) conn; |
| 168 | + TrustManager[] trustAllCerts = new TrustManager[] { |
| 169 | + new X509TrustManager() { |
| 170 | + public java.security.cert.X509Certificate[] getAcceptedIssuers() { |
| 171 | + return null; |
| 172 | + } |
| 173 | + public void checkClientTrusted(X509Certificate[] certs, String authType) { |
| 174 | + } |
| 175 | + public void checkServerTrusted(X509Certificate[] certs, String authType) { |
| 176 | + } |
| 177 | + } |
| 178 | + }; |
| 179 | + SSLContext sc = SSLContext.getInstance("SSL"); |
| 180 | + sc.init(null, trustAllCerts, new java.security.SecureRandom()); |
| 181 | + httpsConn.setSSLSocketFactory(sc.getSocketFactory()); |
| 182 | + httpsConn.setHostnameVerifier((hostname, session) -> true); |
| 183 | + } |
165 | 184 | conn.setReadTimeout(client.getTimeout()); |
166 | 185 | conn.setConnectTimeout(5000); |
167 | 186 | conn.setRequestMethod(method); |
|
0 commit comments