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

后端 未结 3 1791
Happy的楠姐
Happy的楠姐 2021-01-25 04:47

I am connecting to a web service and did not set any connect timeout and read timeout on HttpURLConnection. What is the default connect timeout and read timeout? Is it dependent

3条回答
  •  一生所求
    2021-01-25 05:47

    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.

提交回复
热议问题