HttpURLConnection:是否需要调用connect()?
我见过的许多示例都没有显式调用 connect()
。相反,他们只使用 getInputStream()
或 getResponseCode()
。
我假设所有这些需要连接的 HttpURLConnection 方法都只是调用 connect()
本身?
是否存在必须为 HttpURLConnection 显式调用 connect()
的情况?
Many examples I've seen don't explicitly call connect()
. Instead they just use getInputStream()
or getResponseCode()
.
I'm assuming all of these HttpURLConnection methods that require a connection just call connect()
themselves?
Are there any cases where connect()
must be explicitly called for an HttpURLConnection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,没有案例。它是按需隐式执行的。它甚至在文档中指定。以下是
的摘录URLConnection#connect()
javadoc: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:connect()
是隐含的,并在需要时自动调用。connect()
is implied and automatically invoked when needed.