我在使用Dio api客户端取消请求时遇到问题。
final cancelToken = CancelToken();
final request = host.request(path,
data: data,
queryParameters: query,
options: Options(method: describeEnum(method)),
cancelToken: cancelToken);
final cancelableRequest = CancelableOperation.fromFuture(request, onCancel: () {
cancelToken.cancel();
});
当cancelToken.cancel();时称为我收到DioErrorType.CANCEL,但请求未取消(在Charles Web代理中选中)。我已经尝试过节流请求,但它总是等待响应。
答案 0 :(得分:1)
试试这样写,取消Dio api调用
CancelToken cancelToken = CancelToken();
Request request = host.request(path,
data: data,
queryParameters: query,
options: Options(method: describeEnum(method)),
cancelToken: cancelToken);
// cancel the requests with "cancelled" message.
final cancelableRequest = CancelableOperation.fromFuture(request, onCancel: token.cancel("cancelled"));