HttpURLConnection: Is it necessary to call connect()?

后端 未结 2 1956
面向向阳花
面向向阳花 2020-12-10 05:13

Many examples I\'ve seen don\'t explicitly call connect(). Instead they just use getInputStream() or getResponseCode().

I\'m a

相关标签:
2条回答
  • 2020-12-10 05:22

    connect() is implied and automatically invoked when needed.

    0 讨论(0)
  • 2020-12-10 05:37

    No, there are no cases. It's implicitly executed on demand. It's even specified in the documentation. Here's an extract of the URLConnection#connect() javadoc:

    Operations that depend on being connected, like getContentLength, will implicitly perform the connection, if necessary.

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