使用“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 error)
到目前为止我尝试过的:
What i have tried so far :
1) 首先我得到了空错误对象,所以使用下面的代码解决了它:
@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
时,我知道发生了 timeout
.
So far I have got that there is timeout
happening when I got error object null
.
2) 现在应用程序适用于 Android
和 iOS
和 web
但 timeout
只发生在Android
.
2) Now Application is for Android
and iOS
and web
but timeout
happens only for Android
.
请求的排球日志:
BasicNetwork.logSlowRequests: HTTP response for request
编辑的注释:
在服务器端开发的 Web 服务对于所有三个实例(Android、Web 和 iOS)都是相同的.
Web services develoed at server end is same for all three instances (Android , Web and iOS).
Timeout
当太多用户向服务器发出请求时发生.
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.
如何进行高效的服务调用,解决timeout
的问题.
How can i make efficient service call that can solve problem for timeout
.
任何帮助都会得到认可.
Any help will be appriciated.
谢谢.
推荐答案
由于我试图解决这个问题大约两个月,我没有得到任何完美的解决方案.虽然我分析了一些事实如下:
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.
所以我认为这个问题不是 volley 所特有的,但是您遇到了这个问题,那么我建议通过在下面进行自定义来提高服务器性能 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));
希望它会有所帮助.
随时欢迎提出建议:)
Suggestions are always welcome :)
如果您找到更合适的解决方案,请在下方评论.
Please comment below if you found more proper solution.
谢谢.
这篇关于使用“Volley"发出的服务器请求超时仅适用于 Android 而非 iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!