跳过SSL检查
This commit is contained in:
parent
0e9c893487
commit
728df54510
@ -31,8 +31,8 @@ public class UsceController {
|
||||
private final Logger log = LoggerFactory.getLogger(UsceController.class);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// new UsceController().getUserData();
|
||||
new UsceController().saveSynUser();
|
||||
new UsceController().getUserData();
|
||||
// new UsceController().saveSynUser();
|
||||
}
|
||||
|
||||
@PostMapping("/getUserData")
|
||||
@ -40,9 +40,9 @@ public class UsceController {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String time = sdf.format(System.currentTimeMillis() - (1000 * 60 * 62 * 24));
|
||||
// time = "2024-05-01";
|
||||
String sendUrl = "http://192.168.31.121:8022/ierp/kapi/v2/f9w5/base/bos_user/userQuery";
|
||||
String sendUrl = "https://192.168.31.121:8022/ierp/kapi/v2/f9w5/base/bos_user/userQuery";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
String token = "2095350818281620480_YjTXXBgsnPw1njDkmd7vEw6DCpYTl3AXecvkvO3gelJu41WbhuxYION9M4OB2B722b5zQwcBxmT9OyCbMrW8DqFpCIz9iHmTZRRC01";
|
||||
String token = "2095350818281620480_38r7dCr7UfM45m43Givw964713GJgVwF2xS0uolYf9EvP6kgi8KeRegeih5L6qmyWCr5LjUCeEe8lVwMGsT3KLWz3PxgAwuBCuau01";
|
||||
headers.put("accessToken", token);//放token
|
||||
|
||||
JSONObject params = new JSONObject();
|
||||
|
@ -6,14 +6,20 @@ import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.*;
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -222,12 +228,38 @@ public class HttpClientUtils {
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static TrustManager easyTrustManager = new X509TrustManager() {
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) {
|
||||
// 什么都不做,信任所有客户端证书
|
||||
}
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) {
|
||||
// 什么都不做,信任所有服务器证书
|
||||
}
|
||||
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return new X509Certificate[]{};
|
||||
}
|
||||
};
|
||||
public static SSLContext createEasySSLContext() throws Exception {
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, new TrustManager[]{easyTrustManager}, new SecureRandom());
|
||||
return sslContext;
|
||||
}
|
||||
|
||||
public static HttpClientResult doPostJson(String url, Map<String, String> headers,String json) throws Exception {
|
||||
// 创建httpClient对象
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
SSLContext sslContext = createEasySSLContext();
|
||||
|
||||
// 创建跳过SSL验证的httpClient对象
|
||||
CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
|
||||
|
||||
//创建httpClient对象
|
||||
//CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
|
||||
// 创建http对象
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
|
||||
|
||||
/**
|
||||
* setConnectTimeout:设置连接超时时间,单位毫秒。
|
||||
* setConnectionRequestTimeout:设置从connect Manager(连接池)获取Connection
|
||||
@ -303,6 +335,7 @@ public class HttpClientUtils {
|
||||
*/
|
||||
public static HttpClientResult getHttpClientResult(CloseableHttpResponse httpResponse,
|
||||
CloseableHttpClient httpClient, HttpRequestBase httpMethod) throws Exception {
|
||||
|
||||
// 执行请求
|
||||
httpResponse = httpClient.execute(httpMethod);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user