java 访问接口 获取 接口返回值 二
java 访问接口 获取 接口返回值 2
private void returnInfoMap(String param) {
String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost post = new HttpPost(url);
HttpEntity entity = new StringEntity(param, "UTF-8");
post.setEntity(entity);
post.setHeader("Content-Type", "application/xml; charset=UTF-8");
HttpResponse httpResponse = null;
String response = null;
try {
httpResponse = httpClient.execute(post);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
response = EntityUtils.toString(httpResponse.getEntity(),
"UTF-8");
logger.info("response {}", response);
}
system.out.print(response);
} catch (ClientProtocolException e) {
e.getMessage();
} catch (IOException e) {
e.getMessage();
} finally {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
private void returnInfoMap(String param) {
String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost post = new HttpPost(url);
HttpEntity entity = new StringEntity(param, "UTF-8");
post.setEntity(entity);
post.setHeader("Content-Type", "application/xml; charset=UTF-8");
HttpResponse httpResponse = null;
String response = null;
try {
httpResponse = httpClient.execute(post);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
response = EntityUtils.toString(httpResponse.getEntity(),
"UTF-8");
logger.info("response {}", response);
}
system.out.print(response);
} catch (ClientProtocolException e) {
e.getMessage();
} catch (IOException e) {
e.getMessage();
} finally {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}