//设置超时时间
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
httpClient.getHttpConnectionManager().getParams().setSoTimeout(5000);
/**
* 清缓存(排号系统)
* @return
*/
public String clearCacheHttp(){
//1.构造HttpClient的实例
HttpClient httpClient = new HttpClient();
httpClient.getParams().setContentCharset("utf-8");
//设置超时时间
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
httpClient.getHttpConnectionManager().getParams().setSoTimeout(5000);
//2.构造PostMethod的实例
PostMethod postMethod = new PostMethod(httpServerUrlGlobal);
//like12 add,20160511,中文转码 //在头文件中设置转码
postMethod.addRequestHeader("Content-Type",
"application/x-www-form-urlencoded;charset=utf-8");
//3.把参数值放入到PostMethod对象中
//方式1:
NameValuePair[] data = {
new NameValuePair("queryMode", "clearCache")
};
postMethod.setRequestBody(data);
try {
// 4.执行postMethod,调用http接口
httpClient.executeMethod(postMethod);//200
/*//5.读取内容
String responseMsg = postMethod.getResponseBodyAsString().trim();
System.out.println("responseMsg:" + responseMsg);*/
//6.处理返回的内容
/*JSONObject jsonObject = JSONObject.fromObject(responseMsg);
String fileStr = jsonObject.getString("returnVal1");
//System.out.println("获取返回值成功,Size:" + fileStr.length());
if("fail".equals(fileStr)){
System.out.println("失败,返回值为'fail'");
return "向服务器请求图片失败";
}*/
} catch (Exception e) {
e.printStackTrace();
} finally {
//7.释放连接
postMethod.releaseConnection();
}
return "success";
}