gpt4 book ai didi

android - 即使连接超时和读取超时设置为默认值(无限),接收请求超时?

转载 作者:行者123 更新时间:2023-11-29 18:12:25 27 4
gpt4 key购买 nike

我正在连接到 Web 服务,但没有在 HttpURLConnection 上设置任何连接超时和读取超时。默认的连接超时和读取超时是多少?它依赖于Android手机吗?或者 Android/Java 是否有自己的超时默认值?

当我尝试获取连接超时值 (getConnectTimeout()) 和读取超时值 (getReadTimeout()) 时,它返回值 0,我assume 相当于无穷大。但是,即使它们的值为 0,有时我仍会收到请求超时错误。所以它们的值不可能等于无穷大。有人可以启发我吗?

最佳答案

你做过研究吗? documentation 中详细说明了默认值.以下是相关部分:

public void setConnectTimeout (int timeout) Since: API Level 1

Sets the timeout value in milliseconds for establishing the connection to the resource pointed by this URLConnection instance. A SocketTimeoutException is thrown if the connection could not be established in this time. Default is 0 which stands for an infinite timeout.

public void setReadTimeout (int timeout) Since: API Level 1

Sets the timeout value in milliseconds for reading from the input stream of an established connection to the resource. A SocketTimeoutException is thrown if the connection could not be established in this time. Default is 0 which stands for an infinite timeout.

还有关于超时的注释:

URLConnection supports two timeouts: a connect timeout and a read timeout. By default, operations never time out.

您连接的服务器可能会使您的客户端超时。

关于android - 即使连接超时和读取超时设置为默认值(无限),接收请求超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9986712/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com