//设置超时时间 httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000); httpClient.getHttpConnectionManager().getParams().setSoTimeout(5000);
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的实例 String url = httpServerGlobal; PostMethod postMethod = new PostMethod(url); //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 //6.处理返回的内容 } catch (Exception e) { e.printStackTrace(); } finally { //7.释放连接 postMethod.releaseConnection(); } return "success"; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)