public static String doPost(String params){
String result = null;
InputStream is = null;
HttpClient httpClient = new HttpClient();
PostMethod method = new PostMethod(url);
method.setRequestHeader("Content-Type","application/json;charset=UTF-8");
method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,charset);
try {
RequestEntity requestEntity = new StringRequestEntity(params.toString(),"text/xml","UTF-8");
method.setRequestEntity(requestEntity);
httpClient.executeMethod(method);
// 读取响应
is = method.getResponseBodyAsStream();
result = IOUtils.toString(is,charset);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (method != null) {
method.releaseConnection();
}
if (is != null) {
try {
is.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
return result;
}
HttpClient doPost
最新推荐文章于 2024-04-20 17:19:55 发布