我想发送永不返回响应的异步请求(日志记录,业务事件等)。这是由Retrofit支持吗?
答案 0 :(得分:10)
使用空回调:
public final class Callbacks {
private static final Callback<Object> EMPTY = new Callback<Object> {
@Override public void success(Object value, Response response) {}
@Override public void failure(RetrofitError error) {}
}
@SuppressWarnings("unchecked")
public static <T> Callback<T> empty() {
return (Callback<T>) EMPTY;
}
}
然后在你的代码中:
apiService.someEndpoint(Callbacks.empty());