当retrofit.client.UrlConnectionClient用作客户端如何取消正在进行的改造要求? [英] How to cancel ongoing request in retrofit when retrofit.client.UrlConnectionClient is used as client?

查看:222
本文介绍了当retrofit.client.UrlConnectionClient用作客户端如何取消正在进行的改造要求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用HTTP调用改造在我的Andr​​oid应用程序,并retrofit.client.UrlConnectionClient作为客户端,同时建立适配器。

I am using retrofit for http calls in my Android application and retrofit.client.UrlConnectionClient as the client while building the adapter.

RestAdapter.Builder builder = new RestAdapter.Builder()
            .setEndpoint(url)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setClient(
                    new Client.Provider() {
                        public Client get() {
                            return new UrlConnectionClient() {
                                @Override
                                protected HttpURLConnection openConnection(Request request)
                                        throws IOException {
                                    HttpURLConnection connection = super.openConnection(request);
                                    connection.setConnectTimeout(connectionTimeout);
                                    return connection;
                                }

我想设置成我用UrlConnectionClient为我的客户超时。我无法找到与其他客户端一样OkHttp的一种方式。

I wanted to set the timeout so I have used UrlConnectionClient as my client. I could not find a way with other clients like OkHttp.

问题是:我如何取消正在进行的请求。

Question is : How can I cancel the ongoing request ?.

我已经看到了类似的帖子@ <一个href=\"http://stackoverflow.com/questions/18131382/using-squares-retrofit-client-is-it-possible-to-cancel-an-in-progress-request\">Using广场的改造客户,是否有可能取消正在进行的请求?如果是的话怎么样?但我的code会得到非常复杂的,如果我尝试添加自己的遗嘱执行人,并尝试取消使用该请求。我期待,如果有我现有的code更好的方式稍微

I have seen a similar post @ Using Square's Retrofit Client, is it possible to cancel an in progress request? If so how? but my code would get really complex if I try to add my own executors and try to cancel the request using that. I am looking if there is slightly a better way with my existing code.

我也看到Retorofit V2.0有计划,重试和取消,但不知道时将被释放..的 https://github.com/square/retrofit/issues/297

I also see that Retorofit V2.0 has plan for Retry and Cancel but not sure when that would be released..https://github.com/square/retrofit/issues/297

需要帮助!
事实上,我还需要一种方法使用相同的code重试。

Need help ! In fact I also need a way to retry with the same code.

推荐答案

自从2.0.0-β2这一直是可用(的 https://github.com/square/retrofit/releases/tag/parent-2.0.0-beta2 )。我不知道是否有一个文档,解释这一点,但这里是链接到API:结果
http://square.github.io/retrofit /2.x/retrofit/retrofit/Call.html#cancel--

This has been available since 2.0.0-beta2 (https://github.com/square/retrofit/releases/tag/parent-2.0.0-beta2). I don't know if there is a doc that explains that but here is the link to API:
http://square.github.io/retrofit/2.x/retrofit/retrofit/Call.html#cancel--

通话API允许通过Clone'ing的要求做重试为好。

'Call' API allows to do Retry as well by 'Clone'ing the request.

这篇关于当retrofit.client.UrlConnectionClient用作客户端如何取消正在进行的改造要求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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