The code below is executed with the hint "java.io.IOException:Attempted read from closed stream."
@Test Public voidtest_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 voidhttpget (String url) {closeablehttpclient httpClient= Httpclients.createdefault ();//Establish HttpClientHttpGet HttpGet =NewHttpGet (URL);//Establish HttpGetSYSTEM.OUT.PRINTLN ("Get Request Address:" +Httpget.geturi ()); Try{closeablehttpresponse response= Httpclient.execute (HttpGet);//perform a GET request and save the resultSYSTEM.OUT.PRINTLN ("Get Request returned status code:" +response.getstatusline (). Getstatuscode ()); Httpentity httpentity= Response.getentity ();//Convert saved response to Entities Try { if(Httpentity! =NULL) {{System.out.println (The response value returned by the GET request: "+entityutils.tostring (httpentity)); System.out.println ("LT's Value:" +entityutils.tostring (httpentity). Split ("Lt:\") [1].split ("\", ") [0]); } } } finally{entityutils.consume (httpentity);//Close EntityResponse.close ();//Close Response } } Catch(IOException e) {e.printstacktrace (); } finally { Try{httpclient.close ();//Close HttpClient}Catch(IOException e) {e.printstacktrace (); } } }The reason for this is to specifically point out the following 2 outputs in my script, which call 2 entityutils.tostring (httpentity) in this output, and according to HttpClient's official instructions, entityutils.tostring ( Httpentity) This is called once and will be automatically destroyed, and I call 2 times all the error
SYSTEM.OUT.PRINTLN ("Response value returned by GET request:" + entityutils.tostring (httpentity));
System.out.println ("LT's Value:" +entityutils.tostring (httpentity). Split ("Lt:\" ") [1].split (" \ ",") [0]);
So the 2 output script is changed to the following, as long as the call is good
String responsestr=entityutils.tostring (httpentity);
SYSTEM.OUT.PRINTLN ("Get request Returns the response value:" + responsestr);
String str=responsestr.split ("lt:\") [1].split ("\", ") [0];
System.out.println ("LT's Value:" +STR);
Java.io.IOException:Attempted read from closed stream