Retrofit callback get response body

前端 未结 9 1122
星月不相逢
星月不相逢 2020-12-05 04:05

I am testing Retrofit to compare it with Volley and I am struggling to get the response from my requests. For example, I do something like this:

RestAdapter          


        
相关标签:
9条回答
  • 2020-12-05 04:50

    Just do it like this:

    ModelClass modelclass=response.response.body()
    System.out.println("****************-----retro rsp----1-------"+modelclass.getMessage());
    
    0 讨论(0)
  • 2020-12-05 04:55

    in your model of response press cmd+n and override "toString" method and only call as response.toString();

    @Override
    public String toString() {
        return "{" +
                "key_one='" + var_keyone + '\'' +
                ", key_two='" + var_keytwo + '\'' +
                '}';
    }
    
    0 讨论(0)
  • 2020-12-05 04:59

    With version 2.1.0, you can get the content as

    public void onResponse(Call<T> call, Response<T> response) {
        String errorString = response.errorBody().string();
    }
    
    0 讨论(0)
提交回复
热议问题