several requests from one HttpURLConnection

后端 未结 2 958
广开言路
广开言路 2021-01-04 02:43

How can I do several request in one HttpURLConnection with Java?

 URL url = new URL(\"http://my.com\");
 HttpURLConnection connection = (HttpURLConnection)ur         


        
2条回答
  •  时光取名叫无心
    2021-01-04 03:08

    Beyond the correct answer, maybe what you actually want is reuse of the underlying TCP connection, aka "persistent connections", which are indeed supported by JDK's HttpURLConnection. So you don't need to use other http libs for that reason; although there are other legitimate reason, possibly performance (but not necessarily, depends on use case, library).

提交回复
热议问题