/**
* 基于Https post 方式通讯协议数据访问接口
* @param ipAddress ip地址
* @param visitUrl 通讯接口地址
* @param userName 用户账号
* @param passWord 用户密码
* @return
*/
public static Map<String,Object> doPost(String ipAddress,String visitUrl,String userName,String passWord)
{
Map<String,Object> resultMap = new HashMap<String,Object>();
String resultStr = "";
int resultCode = 0;
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(ipAddress, 5000),new UsernamePasswordCredentials(userName, passWord));
CloseableHttpClient httpclient = null;
CloseableHttpResponse response = null;
try
{
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial((chain, authType)->true).build();
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory (sslContext,
new String[] {"SSLv2Hello", "SSLv3", "TLSv1","TLSv1.1", "TLSv1.2" },
null,NoopHostnameVerifier.INSTANCE);
httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider)
.setSSLSocketFactory(sslConnectionSocketFactory)
.build();
HttpPost httppost = new HttpPost(visitUrl);
// String postParams ="{\"strategy\":\"rf\",\"frequency\":[\"2.4GHz\",\"5.8GHz\"],\"duration\":60}";
// System.out.println(postParams);
// HttpEntity httpEntity = new StringEntity(postParams);
// httppost.setEntity(httpEntity);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(20000)
.setConnectionRequestTimeout(20000)
.setSocketTimeout(20000).build();
httppost.setConfig(requestConfig);
response = httpclient.execute(httppost);
resultCode = response.getStatusLine().getStatusCode();
// resultStr = EntityUtils.toString(response.getEntity());
resultMap.put("resultCode", resultCode);
resultMap.put("resultStr", resultStr);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
if(response != null)
{
try
{
response.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
if(httpclient != null)
{
try
{
httpclient.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
return resultMap;
}