场景:页面查询时调用外部接口(含参数),对获取的数据进行封装返回页面
url为外部接口,放入硬编码中;params为查询参数
HttpUtil为工具类,doPost方法:
public static String doPost(String apiUrl, Map<String, Object> params) throws Exception {
CloseableHttpClient httpClient = createSSLClientDefault();// HttpClients.createDefault();
String httpStr = null;
HttpPost httpPost = new HttpPost(apiUrl.trim());
CloseableHttpResponse response = null;
try {
httpPost.setConfig(requestConfig);
if (null == params) {
params = new HashMap<String, Object>();
}
List<NameValueP