Closing an HttpURLConnection before the response is complete

后端 未结 3 1576
春和景丽
春和景丽 2021-01-18 10:36

Background

I\'m using HttpURLConnection on the client side to consume a response in an HTTP streaming (server push) situation. Although the server may close the co

3条回答
  •  北海茫月
    2021-01-18 11:25

    Another workaround is to wrap the input stream in a Channel and use that (Channels.newChannel), as suggested in the workaround to JDK-4329256. That will cause the underlying input stream to be closed when the thread is interrupted. However, there is a comment in the JDK that its not really interruptible. In my testing it seems to work. I've asked here for more information.

提交回复
热议问题