/**
* @Description 普通 post请求-JSON格式
* @param data 请求参数
* @param requestUrl 请求地址
* @return 请求返回结果
**/
public static String requestJsonPost(final String data, final String requestUrl) throws IOException {
HttpClient httpClient = getHttpClient();
HttpPost httpPost = new HttpPost(requestUrl);
StringEntity stringEntity = new StringEntity(data, ContentType.APPLICATION_JSON);
httpPost.setEntity(stringEntity);
try {
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
String result = EntityUtils.toString(httpEntity, "UTF-8");
return result;
} catch (IOException e) {
e.printStackTrace();
throw new IOException(e);
}
}
/**
* @Description 普通 post请求
* @param data 请求参数
* @param requestUrl 请求地址
* @return 请求返回结果
**/
public static String requestPost(final String data, final String requestUrl) throws IOException {
HttpClient httpClient = getHttpClient();
HttpPost httpPost = new HttpPost(requestUrl);
StringEntity stringEntity = new StringEntity(data, "UTF-8");
httpPost.setEntity(stringEntity);
try {
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
String result = EntityUtils.toString(httpEntity, "UTF-8");
return result;
} catch (IOException e) {
e.printStackTrace();
throw new IOException(e);
}
}