Android Retrofit2 POST调用不会触发HTTP请求

时间:2018-03-24 04:54:37

标签: java android retrofit retrofit2

我在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。

知道我缺少什么吗?

1 个答案:

答案 0 :(得分:1)

Retrofit的rx-adapter创建可观察,即在您订阅之前它不会做任何事情。所以问题在于,您没有订阅mUserApi.doSomething(idList); API调用。

所以只需订阅它&amp;它会被叫到。此外,我不确定mAccountManager.onAuthChange()的代码,但您应该在subscribe内部使用onError部分以避免UndeliverableException