HttpURLConnection:是否需要调用connect()?

发布于 2024-09-01 03:14:12 字数 259 浏览 3 评论 0原文

我见过的许多示例都没有显式调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

德意的啸 2024-09-08 03:14:12

不,没有案例。它是按需隐式执行的。它甚至在文档中指定。以下是 的摘录URLConnection#connect() javadoc:

如果需要,依赖于连接的操作(例如 getContentLength)将隐式执行连接。

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.

☆獨立☆ 2024-09-08 03:14:12

connect() 是隐含的,并在需要时自动调用。

connect() is implied and automatically invoked when needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文