CloseableHttpClient的使用

String content = null;
		try {
			// 创建CloseableHttpClient
			CloseableHttpClient client = HttpClientBuilder.create().build();
			HttpPost httpPost = new HttpPost("请求地址");//地址
			httpPost.setHeader("x-tif-paasid", paasId);//请求头
			RequestConfig config = RequestConfig.custom().setConnectTimeout("超时时间").build();
			httpPost.setConfig(config);
			HttpEntity entity = new StringEntity(params, "utf-8"); // 参数设置utf8编码
			httpPost.setEntity(entity);
			CloseableHttpResponse response = client.execute(httpPost);//消息发送
			content = EntityUtils.toString(response.getEntity());//获取返回值
		} catch (Exception e) {
			e.printStackTrace();
		}
		return content;

你可能感兴趣的:(Java基础,http,https,网络协议)