At Okhttp2.0,we can okhttpclient.cancel(tag). But at Okhttp3.0,How to cancel a request?
Well,when using okHttp3, you can set tag in request,like:Request request = new Request.Builder()
.url(url)
.tag("sss").build();
so,when you wanna cancel the request with tag "sss",you can do like this:
for(Call call : mOkHttpClient.dispatcher().queuedCalls()) {
if(call.request().tag().equals("sss"))
call.cancel();
}
for(Call call : mOkHttpClient.dispatcher().runningCalls()) {
if(call.request().tag().equals("sss"))
call.cancel();
}
How to know if the call was cancelled ?
isCanceled()
On Sun, Mar 19, 2017, 3:00 PM abdullah notifications@github.com wrote:
How to know if the call was cancelled ?
—
You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub
https://github.com/square/okhttp/issues/2550#issuecomment-287638560, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAEEEWsxDaonbjLHg9JCywmLi6TDDHc5ks5rnXswgaJpZM4Ib1bQ
.
Most helpful comment
Well,when using okHttp3, you can set tag in request,like:Request request = new Request.Builder()
.url(url)
.tag("sss").build();
so,when you wanna cancel the request with tag "sss",you can do like this:
for(Call call : mOkHttpClient.dispatcher().queuedCalls()) {
if(call.request().tag().equals("sss"))
call.cancel();
}
for(Call call : mOkHttpClient.dispatcher().runningCalls()) {
if(call.request().tag().equals("sss"))
call.cancel();
}