Java – transformation 2.0b2: how to get InputStream from response?
•
Java
I'm using retrofit 2.0b2 After getting the response, I try to get an InputStream from the response:
Response<JsonNode> response = call.execute(); InputStream is = response.raw().body().byteStream();
But the application keeps throwing:
java.lang.IllegalStateException: Cannot read raw response body of a converted body. at retrofit.OkHttpCall$NoContentResponseBody.source(OkHttpCall.java:184) at com.squareup.okhttp.ResponseBody.byteStream(ResponseBody.java:43) at ...
Although the response returned correctly What did I do wrong here?
Solution
If you want the original stream, please tell the modification to return an okhttp ResponseBody
Response<ResponseBody> response = call.execute(); InputStream is = response.body().byteStream();
Remember to update your interface
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码