Caused by: retrofit.RetrofitError: method POST must have a request body

后端 未结 6 1631
悲&欢浪女
悲&欢浪女 2021-01-02 01:12

I am using retrofit to make a post api call, I am getting the following error while trying to hit the endpoint.

     Caused by: rx.exceptions.OnErrorNotImple         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 01:47

    It looks like Retrofit wants POST requests to have a payload. There's already an issue for it: https://github.com/square/retrofit/issues/854

    As a workaround, you could do something like this:

    @POST("/service/v2/auth/ip-address")
    rx.Observable verifyIP(@Body Object dummy);
    

    and then do:

    LoginService service = CKRestClient.get().create(LoginService.class);
    
    service.verifyIP(null).observeOn(AndroidSchedulers.mainThread()).subscribe(
      new Action1() {
        @Override
        public void call(AuthState authState) {
          // ...
        }
      });
    });
    

    Or, if service.verifyIP(null) throws a NPE, replace it with service.verifyIP("") or similar.

提交回复
热议问题