java.io.IOException: Attempted read from closed stream.

前言

使用HttpClient启动报错


java.io.IOException: Attempted read from closed stream.
	at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:165) ~[httpcore-4.4.6.jar:4.4.6]
	at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:135) ~[httpclient-4.5.3.jar:4.5.3]
	at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) ~[na:1.8.0_261]
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) ~[na:1.8.0_261]
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) ~[na:1.8.0_261]
	at java.io.InputStreamReader.read(InputStreamReader.java:184) ~[na:1.8.0_261]
	at java.io.Reader.read(Reader.java:140) ~[na:1.8.0_261]
	at org.apache.http.util.EntityUtils.toString(EntityUtils.java:225) ~[httpcore- 

原因

EntityUtils.toString(HttpEntity)方法中操作的是流数据,流数据是一次性数据所以同一个 HttpEntity不能使用多次该方法

解决

注释掉你的输出或者引用的地方就行了,传递出输出只有一次
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/HezhezhiyuLe/article/details/108795769