https使用IP地址访问,报错:set the CXF client TLS configuration property “disableCNCheck“ to true

要信任所有的证书,并关闭校验

	public String doPost(String method, Long curTime, String data) throws Exception {
		String nonce = Const.getStr(Math.random());
		String checkSum = encode("sha1", getConfigByKey("sh2appSecret")+nonce+curTime);
		String params = "?appId="+getConfigByKey("sh2Appid")+"&nonce="+nonce+"&curTime="+curTime+"&checkSum="+checkSum;

		HttpPost httpPost = new HttpPost(getConfigByKey("sh2Url")+method+getConfigByKey("sh2ParkingId")+params);
		RequestConfig requestConfig = RequestConfig.custom()
				.setConnectionRequestTimeout(2000)
		        .setConnectTimeout(5000)
		        .setSocketTimeout(20000).build();

		//信任所有证书,关闭主机名校验
		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
				SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(),
				NoopHostnameVerifier.INSTANCE);

//		CloseableHttpClient httpclient = HttpClients.createDefault();
		CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();

		httpPost.setConfig(requestConfig);
		httpPost.setHeader("Accept", "application/json");
		httpPost.setHeader("Content-Type", "application/json");
		String sign=encode("md5", getConfigByKey("sh2appSecret")+"|"+data);
		httpPost.setHeader("sign", sign);
		StringEntity entity = new StringEntity(data, "UTF-8");
		httpPost.setEntity(entity);
		CloseableHttpResponse response = null;
		try {
			//LOG.info("SH2--" + method + ",sign:" + sign+",data="+data);
			response = httpclient.execute(httpPost);
			StatusLine status = response.getStatusLine();
			int state = status.getStatusCode();
			if (state == HttpStatus.SC_OK) {
				HttpEntity responseEntity = response.getEntity();
				String jsonString = EntityUtils.toString(responseEntity);
				return jsonString;
			}
			LOG.info("SH2--" + method + ",状态码是:" + state);
		} finally {
			if (response != null) {
				try {
					response.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			try {
				httpclient.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木小百99

听说打赏的人都发财了

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值