resttemlate请求头无效 换种方式请求外部接口
public Map<String, Object> postClient(String url, String timeStamp, Object param) throws IOException {
String key = SpringUtil.getProperty("appkey");
String encodedQuery = "";
encodedQuery += "appkey=" + key;
if (!url.contains("?")) {
url += "?" + encodedQuery;
} else {
url += "&" + encodedQuery;
}
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type","application/json");
httpPost.addHeader(SignInfoEnum.SIGN.getKey(), SignInfoEnum.SIGN.getValue());
httpPost.addHeader("timestamp","1243546432346");
StringEntity stringEntity = new StringEntity(JSON.toJSONString(param),"utf-8");
httpPost.setEntity(stringEntity);
CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse execute = client.execute(httpPost);
org.apache.http.HttpEntity entity = execute.getEntity();
String result = EntityUtils.toString(entity);
return JSON.parseObject(result);
}