@Test public void test_temp(){ String url="http://ssov1.59iedu.com/login?TARGET=http://med.ihbedu.com:80/gateway/web/sso/auth&js&callback=loginThen&1470491151264&nocache=1470491171451"; this.HttpGet(url); } public void HttpGet(String url) { CloseableHttpClient httpClient = HttpClients.createDefault();//建立httpclient HttpGet httpGet = new HttpGet(url);//建立httpget System.out.println("get请求的地址:" + httpGet.getURI()); try { CloseableHttpResponse response = httpClient.execute(httpGet);//执行get请求,并结果保存 System.out.println("get请求返回的状态码:" + response.getStatusLine().getStatusCode()); HttpEntity httpEntity = response.getEntity();//将保存的response转为实体 try { if (httpEntity != null) { { System.out.println("get请求返回的response值:" + EntityUtils.toString(httpEntity)); System.out.println("lt的值:"+EntityUtils.toString(httpEntity).split("lt:\"")[1].split("\",")[0]); } } } finally { EntityUtils.consume(httpEntity);//关闭实体 response.close();//关闭response } } catch (IOException e) { e.printStackTrace(); } finally { try { httpClient.close();//关闭httpclient } catch (IOException e) { e.printStackTrace(); } } }
System.out.println("get请求返回的response值:" + EntityUtils.toString(httpEntity));
System.out.println("lt的值:"+EntityUtils.toString(httpEntity).split("lt:\"")[1].split("\",")[0]);
String responseStr=EntityUtils.toString(httpEntity);
System.out.println("get请求返回的response值:" + responseStr);
String str=responseStr.split("lt:\"")[1].split("\",")[0];
System.out.println("lt的值:"+str);
java.io.IOException: Attempted read from closed stream
原文:http://www.cnblogs.com/xxyBlogs/p/5745038.html