post请求
public void post() throws IOException {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://localhost:5000/merge_excel_cell");
httpPost.addHeader("Content-Type", "application/json");
JSONObject parm = new JSONObject();
// parm.put("templateFilePath", tplPath);
// parm.put("outputFilePath", outPutPath + "/" + outputFileName);
// parm.put("data", data);
httpPost.setEntity(new StringEntity(parm.toString(), "utf-8"));
CloseableHttpResponse response = httpClient.execute(httpPost);
String responseMag = EntityUtils.toString(response.getEntity(), "utf-8");
System.err.println(responseMag);
}
get请求
public static String getHttpGet(String url) {
try {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
HttpUriRequest httpget = RequestBuilder.get().setUri(new URI(url)).build();
CloseableHttpResponse response = httpclient.execute(httpget);
try {
String responseMag = EntityUtils.toString(response.getEntity());
return responseMag;
// System.out.println(EntityUtils.toString(response.getEntity()));
} finally {
response.close();
}
} finally {
httpclient.close();
}
} catch (Exception e) {
return null;
}
}