Retrofit callback get response body

前端 未结 9 1236
星月不相逢
星月不相逢 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条回答
  •  猫巷女王i
    2020-12-05 04:38

    Another solution would be to do something like the following:

      private static String bodyAsString(RequestBody body) {
        try {
          Buffer buffer = new Buffer();
          body.writeTo(buffer);
          return buffer.readString(body.contentType().charset());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
    

    Taken from https://github.com/square/okhttp/blob/master/okcurl/src/test/java/com/squareup/okhttp/curl/MainTest.java#L93-L101

提交回复
热议问题