private String postHttpRequest(String objStr,String url){
HttpClient client = new DefaultHttpClient();
String bodyStr = "";
HttpPost httpPost = new HttpPost(url);
try {
StringEntity reqEntity = new StringEntity(objStr); //组装请求数据
httpPost.setEntity(reqEntity);
} catch (Exception e) {
log.error("postHttpRequest get entity error", e);
return bodyStr;
}
try {
HttpResponse response = client.execute(httpPost); //发送请求
HttpEntity entity = response.getEntity();
bodyStr = EntityUtils.toString(entity); //得到结果内容
}catch (Exception e) {
log.error("postHttpRequest execute post error", e);
return bodyStr;
}
log.info("bodyStr : " + bodyStr);
return bodyStr;
}
Httpclient POST
最新推荐文章于 2023-02-14 21:57:28 发布