Receiving request timeout even though connect timeout and read timeout is set to default (infinite)?

对着背影说爱祢 提交于 2019-12-02 07:00:44

Did you do any research? The defaults are detailed in the documentation. Here's the relevant parts:

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.

Also there is this note on timeouts:

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

It might be possible that the server you are connecting to is timing out your client.

If the getConnectTimeout and getReadTimeout from the object return zero, then that does indeed mean infinity. This is inherited from the underlying URLConnection class.

It may be that the exception you're receiving is not a SocketTimeoutException at all, you should verify this - it's possible to get IOException thrown regardless of the timeout settings.

The Javadoc for connect() is incorrect. Zero gives you the platform connect timeout, which is not infinite, but around a minute. You can only decrease this value with the timeout parameter to connect(), not increase it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!