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

后端 未结 6 1668
悲&欢浪女
悲&欢浪女 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:44

    @Body String emptyBody wasn't working for me as backend server I was working with, was returning Bad request and not accepting empty string as a body.

    I've just sent empty JSON instead of empty String

    @POST("/some/url) Observable doThing(@Body JsonElement empty);

    and then I just called my method like this:

    doThing(new JsonObject());

    Hope it will help if someone has similar problem.

提交回复
热议问题