How to reset URLConnection in java?

╄→гoц情女王★ 提交于 2019-12-06 11:17:38

URLConnection is an easy but somewhat "dumb" class. I can suggest you to do it the Java way: instantiate a new URLConnection. ;) Java is not really a language that encorages reusage of objects.

You can try resetting the input stream, see the docs for more info, but I don't think it will do another GET. Who knows how the concrete implementation behind InputStream and OutputStream of URLConnections is done.

EDIT: I don't guarantee anything, but you could also try to disconnect() and then connect() again. Never tried it, see if it works.

By default there is no way. If you really want this feature, you have write some code for that. Write a URLHandler which gives a socket wrapper, that does buffering. Implement reset methods() as you like.

Thanks, Ramesh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!