修改在自定义证书下,https请求报错

master
星期八 5 years ago
parent eeb83bd256
commit 38d944cb0b
  1. 18
      panda-code/src/main/java/org/panda/code/uitl/http/HttpKit.java

@ -20,11 +20,7 @@ import java.security.cert.X509Certificate;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.*;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
/** /**
@ -68,6 +64,12 @@ public class HttpKit {
http.setSSLSocketFactory(ssf); http.setSSLSocketFactory(ssf);
http.setDoOutput(true); http.setDoOutput(true);
http.setDoInput(true); http.setDoInput(true);
http.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
http.connect(); http.connect();
InputStream in = http.getInputStream(); InputStream in = http.getInputStream();
@ -133,6 +135,12 @@ public class HttpKit {
http.setSSLSocketFactory(ssf); http.setSSLSocketFactory(ssf);
http.setDoOutput(true); http.setDoOutput(true);
http.setDoInput(true); http.setDoInput(true);
http.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
});
http.connect(); http.connect();
OutputStream out = http.getOutputStream(); OutputStream out = http.getOutputStream();
out.write(params.getBytes("UTF-8")); out.write(params.getBytes("UTF-8"));

Loading…
Cancel
Save