CloseableHttpClient httpclient;
try
{
httpclient = HttpClients.custom().setSSLSocketFactory( createSSLFactory(
jksPath
,
jksPwd
)).build();
}
catch
(Exception e1) {
httpclient = HttpClientBuilder. create().build();
e1.printStackTrace();
}
HttpHost targetHost =
new
HttpHost(
host
,
port
,
"https"
);
JSONObject json =
new
JSONObject();
json.put(
"id"
, id);
json.put(
"method"
, method);
if
(!CollectionUtils. isEmpty(params)) {
JSONArray array =
new
JSONArray();
array.addAll(params);
json.put(
"params"
, params);
}
JSONObject responseJsonObj =
null
;
try
{
CredentialsProvider credsProvider =
new
BasicCredentialsProvider();
credsProvider.setCredentials(
new
AuthScope(
host
,
port
),
new
UsernamePasswordCredentials(
rpcuser
,
rpcpwd
));
// Create AuthCache instance
AuthCache authCache =
new
BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth =
new
BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);
context.setAuthCache(authCache);
HttpPost httppost =
new
HttpPost(
url
);
StringEntity myEntity =
new
StringEntity(json.toJSONString());
httppost.setEntity(myEntity);
CloseableHttpResponse response = httpclient.execute(targetHost, httppost, context);
HttpEntity entity = response.getEntity();