这是一个发送post请求的工具类,在本地可以正常获取到返回的数据,上传到服务器后,无法获取到数据,而且日志记录显示未发生异常
public static JSONObject doPost(String url,JSONObject json){
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
JSONObject response = null;
try {
StringEntity s = new StringEntity(json.toString());
s.setContentEncoding("UTF-8");
s.setContentType("application/json");//发送json数据需要设置contentType
post.setEntity(s);
HttpResponse res = client.execute(post);
if(res.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
String result = EntityUtils.toString(res.getEntity());// 返回json格式:
logger.info("result:"+result);
response = JSON.parseObject(result);
}
} catch (Exception e) {
logger.error("error:"+e.getMessage());
e.printStackTrace();
}
logger.info("请求结束");
return response;
}