HttpClient client = new HttpClient(); GetMethod get=new GetMethod("http://www.baidu.com"); try { client.executeMethod(get); } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Cookie[] cookies= client.getState().getCookies(); if (cookies.length == 0) { //如果获取cookies为空 System.out.println( "None" ); } else { for ( int i = 0; i < cookies.length; i++) { System.out.println(cookies.length); String a=cookies[i].toString();//获取cookies里面所有信息 System.out.println(a); } }
时间: 2024-10-03 02:48:16