Safe use of HttpURLConnection

后端 未结 7 1669
清歌不尽
清歌不尽 2020-11-29 19:33

When using HttpURLConnection does the InputStream need to be closed if we do not \'get\' and use it?

i.e. is this safe?

HttpURLConnection conn = (Htt         


        
相关标签:
7条回答
  • 2020-11-29 20:31

    is it safe to close an InputStream before all of it's content has been read

    You need to read all of the data in the input stream before you close it so that the underlying TCP connection gets cached. I have read that it should not be required in latest Java, but it was always mandated to read the whole response for connection re-use.

    Check this post: keep-alive in java6

    0 讨论(0)
提交回复
热议问题