使用“Volley”进行服务器请求的超时时间。仅适用于Android而非iOS [英] Timeout for server request made using "Volley" only on Android not iOS
问题描述
在我的一个应用程序中,我使用 Google 提供的 volley
向服务器发送请求。
In one of my application, I am sending request to server using volley
provided by Google.
问题: onErrorResponse上的超时和错误对象为空(VolleyError错误)
到目前为止我尝试了什么:
What i have tried so far :
1)首先我得到了null错误对象,所以使用下面的代码解决了它:
@Override
protected void deliverResponse(String response) {
super.deliverResponse(response);
}
@Override
public void deliverError(VolleyError error) {
super.deliverError(error);
DebugLog.e("deliverResponse", "getNetworkTimeMs : " + error.getNetworkTimeMs());
}
到目前为止,我已经知道超时
当我收到错误对象时发生 null
。
So far I have got that there is timeout
happening when I got error object null
.
2)现在应用程序是对于 Android
和 iOS
和 web
但超时
仅适用于 Android
。
2) Now Application is for Android
and iOS
and web
but timeout
happens only for Android
.
排球日志请求:
BasicNetwork.logSlowRequests: HTTP response for request
编辑注:
-
网络服务在服务器端开发的所有三个实例(Android,Web和iOS)都相同。
Web services develoed at server end is same for all three instances (Android , Web and iOS).
超时
太多用户向服务器发出请求时会发生这种情况。
Timeout
happens when too many users makes requests to the server.
我已将时间设置为2分钟,但排球时间仅在30秒内超时。
我有很多答案可以改变服务器,但因为不可能有其他解决方案。
I have many answers to change server but as it is not possible so any other solution please.
我还想补充一点,如果我可以获得更多关于何时可以在凌空中超时的信息?
I also like to add that if i can get more information about when timeout can be possible in volley ?
参考资料我已经完成:
httpclient-often-times-out-using-wifi-is-going-fine-with-3g
long_xmlhttprequest_ajax_requests_timeout_on_android
已编辑:
我还设置了重试政策,如下所示:
I have also set retry policy as below:
request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 48,
0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
如果连接超时,我也不想重试。
And also i do not want to retry if connection timeout.
如何进行有效的服务调用,解决超时
的问题。
How can i make efficient service call that can solve problem for timeout
.
任何帮助将是适当的。
谢谢。
推荐答案
正如我所尝试的那样为了解决这个问题大约两个月,我没有得到任何完美的解决方案。虽然我分析了以下一些事实:
As i have tried to get solution of this issue for about two months, I did not get any perfect solution. Though I analyze some facts as below :
- 您可以升级服务器的性能
- 我试过了使用
HttpURLConnection
发出网络服务请求,但仍然遇到同样的问题。
- You can upgrade your server's performance
- I have tried making web-service request using
HttpURLConnection
but still getting same issue over there.
所以我认为这个问题并非具体来自凌空,但你得到这个问题然后我会建议通过自定义以下 RetryPolicy来增加服务器性能
:
So I think this issue is not specific from volley, but you getting this issue then i would suggest to increase server performance with customizing below RetryPolicy
:
int x=2;// retry count
request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 48,
x, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
希望它会有所帮助。
建议随时欢迎:)
如果您找到更合适的解决方案,请在下方发表评论。
Please comment below if you found more proper solution.
谢谢。!
这篇关于使用“Volley”进行服务器请求的超时时间。仅适用于Android而非iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!