我在Android上使用Retrofit2 / RxJava。我的POST通话工作正常。但现在我从另一个地方添加了电话。调用时,没有发送HTTP post请求,没有错误/异常。 HttpInterceptor也没有看到这个电话。在这种情况下,我很难找出我做错了什么。
mAccountManager.onAuthChange()
.subscribeOn(Schedulers.io())
.subscribe(authCode -> {
if (mAccountManager.isLoggedIn(authCode)) {
someOtherApi.getIds()
.subscribeOn(Schedulers.io())
.subscribe(idList -> {
mUserApi.doSomething(idList);
});
}
});
...
@POST("/api/users/dosomething")
Observable<Void> doSomething(@Body IdList idList);
我确保通过放置断点来调用改装api。
知道我缺少什么吗?
答案 0 :(得分:1)
Retrofit的rx-adapter创建冷可观察,即在您订阅之前它不会做任何事情。所以问题在于,您没有订阅mUserApi.doSomething(idList);
API调用。
所以只需订阅它&amp;它会被叫到。此外,我不确定mAccountManager.onAuthChange()
的代码,但您应该在subscribe
内部使用onError部分以避免UndeliverableException