当 retrofit.client.UrlConnectionClient 用作客户端时,如何取消正在进行的改造请求?

How to cancel ongoing request in retrofit when retrofit.client.UrlConnectionClient is used as client?

我在 Android 应用程序和 retrofit.client.UrlConnectionClient 应用程序中使用改造进行 http 调用,同时构建适配器。

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 这样的其他客户端的方法。

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

我见过类似的 post @ Using Square's Retrofit Client, is it possible to cancel an in progress request? If so how? 但如果我尝试添加自己的执行程序并尝试使用它取消请求,我的代码会变得非常复杂。我正在寻找现有代码是否有更好的方法。

我也看到 Retorofit V2.0 有重试和取消的计划,但不确定什么时候发布..https://github.com/square/retrofit/issues/297

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

从 2.0.0-beta2 (https://github.com/square/retrofit/releases/tag/parent-2.0.0-beta2) 开始可用。我不知道是否有文档对此进行解释,但这是 link 到 API:
http://square.github.io/retrofit/2.x/retrofit/retrofit/Call.html#cancel--

'Call' API 也允许通过“克隆”请求进行重试。