httpClient释放链接的问题
时间: 2013-10-11来源:开源中国
前景提要
HDC调试需求开发(15万预算),能者速来!>>>
昨天接触到了httpclient和jsoup,
使用httpclient模拟登陆OA,想抓OA的数据下来,无实在意义,只是练手。
不过在过程中出了一点问题。
public static boolean login(){ HttpGet get = new HttpGet(uri+"/logincheck.php"); List<NameValuePair> params = new ArrayList<NameValuePair>(); //.... try { String str = EntityUtils.toString(new UrlEncodedFormEntity(params)); get.setURI(new URI(get.getURI()+"?"+str)); response = client.execute(get); //.... } catch (Exception e) { e.printStackTrace(); } if(response.getStatusLine().getStatusCode()==200){ System.out.println("登陆成功!"); return true; }else{ return false; } } 这个方法没有问题,不过在登陆之后,我直接访问一个OA里面的新闻页面,去抓数据的时候就会出错。

public static String getNewsContent(){ HttpGet get = new HttpGet(uri+"/general/notify/show"); try { response = client.execute(get); HttpEntity entity = response.getEntity(); String newsContent = EntityUtils.toString(entity); Document doc = Jsoup.parse(newsContent); Elements elements = doc.getElementsByClass("TableLine1"); for(Element element : elements){ System.out.println(element.val()); } } catch (Exception e) { e.printStackTrace(); } return ""; } 在第二次client.execute(get)的时候就会报错。

java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated. Make sure to release the connection before allocating another one.

科技资讯:

科技学院:

科技百科:

科技书籍:

网站大全:

软件大全:

热门排行