即使连接超时和读取超时设置为默认值(无限)接收请求超时? [英] Receiving request timeout even though connect timeout and read timeout is set to default (infinite)?

查看:2884
本文介绍了即使连接超时和读取超时设置为默认值(无限)接收请求超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我连接到Web服务,并没有设置任何连接超时和读取超时的HttpURLConnection的。什么是默认连接超时和读取超时?它是依赖于Android手机?还是Android的/ Java有对超时了自己的默认值?

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 on the Android phone? Or does Android/ Java has its own default value for the timeout?

当我试图让我连接超时的值( getConnectTimeout()),并读取超时( getReadTimeout()),则返回0,我认为是无穷大的等效值。不过,即使它们的值是0,也有我仍然收到一个请求超时错误次数。因此他们的值不能等于无穷大。可有人见识一下吗?

When I try to get the value of my connect timeout (getConnectTimeout()) and read timeout (getReadTimeout()), it returns a value of 0 which I assume is the equivalent of infinity. However, even though their value is 0, there are times that I'm still receiving a request timeout error. So their value can't be equal to infinity. Can someone enlighten me on this?

推荐答案

你有没有做任何研究吗?在默认设置进行了详细的文档。以下是有关部分:

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

公共无效setConnectTimeout(INT超时)自:API级别1

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

设定以毫秒为单位的超时值用于建立连接   要指出此URLConnection实例的资源。一个   SocketTimeoutException如果被抛出,如果连接不能   建立在这个时候。 默认为0,表示无限   暂停。

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.

公共无效setReadTimeout(INT超时)自:API级别1

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

设定在毫秒的超时值用于从输入读出   已建立的连接到资源的流。一个   SocketTimeoutException如果被抛出,如果连接不能   建立在这个时候。 默认为0,表示无限   暂停。

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的支持两个超时:连接超时和   读取超时。默认情况下,操作永不超时。

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.

这篇关于即使连接超时和读取超时设置为默认值(无限)接收请求超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆