在RoboSpice请求android中设置Connection TimeOut

在RoboSpice请求android中设置Connection TimeOut,第1张

概述我在 Android中使用RoboSpice for Rest Api调用,我想在调用中添加30秒的连接超时我将如何 *** 作? 这是我的代码 public class AddBrandsService extends SpringAndroidSpiceRequest<AddBrands.Response> { public final AddBrands.Response 我在 Android中使用RoboSpice for Rest API调用,我想在调用中添加30秒的连接超时我将如何 *** 作?

这是我的代码

public class AddBrandsService extends        SpringAndroIDSpiceRequest<AddBrands.Response> {     public final AddBrands.Response loadDataFromNetwork(){     return getRestTemplate().postForObject(url,request,AddBrands.Response.class);    }    }    this service is called here     private SpiceManager contentManager = new SpiceManager(        JacksonspringAndroIDSpiceService.class);    contentManager.execute(service,lastRequestCacheKey,DurationInMillis.ONE_SECOND,new AddBrandsListner());

提前致谢…

解决方法 这是代码.基本上,你必须在两个不同的实现之间处理androID的版本作为spring androID切换,以避免网络堆栈中的已知错误.不幸的是,两种实现都不共享与超时相关的公共接口.
private voID manageTimeOuts(RestTemplate restTemplate) {    // set timeout for requests    ClIEnthttpRequestFactory factory = restTemplate.getRequestFactory();    if (factory instanceof httpComponentsClIEnthttpRequestFactory) {        httpComponentsClIEnthttpRequestFactory advancedFactory = (httpComponentsClIEnthttpRequestFactory) factory;        advancedFactory.setConnectTimeout(WEBSERVICES_TIMEOUT);        advancedFactory.setReadTimeout(WEBSERVICES_TIMEOUT);    } else if (factory instanceof SimpleClIEnthttpRequestFactory) {        SimpleClIEnthttpRequestFactory advancedFactory = (SimpleClIEnthttpRequestFactory) factory;        advancedFactory.setConnectTimeout(WEBSERVICES_TIMEOUT);        advancedFactory.setReadTimeout(WEBSERVICES_TIMEOUT);    }}
总结

以上是内存溢出为你收集整理的在RoboSpice请求android中设置Connection TimeOut全部内容,希望文章能够帮你解决在RoboSpice请求android中设置Connection TimeOut所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1140935.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存