在 Retrofit 2 中支持 @Streaming [英] Support for @Streaming in Retrofit 2
本文介绍了在 Retrofit 2 中支持 @Streaming的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因为没有 body().in()
(不再),此代码在改造 2 中不起作用:
Because there is no body().in()
(anymore), this code does not work in retrofit 2:
interface Service {
@Get("...")
@Streaming
Response getData();
}
try (InputStream in = service.getData().getBody().in()) {
...
}
我找到的唯一方法就是这个.这是正确的吗?
Only way I found is this. Is this correct?
try (InputStream in = service.getData().raw().body().byteStream()) {
...
}
推荐答案
有点晚了,但我今天遇到了同样的问题,所以这是我发现和使用的:
A bit late but I had the same issue today so here's what I found and use :
interface Service {
@GET("...")
@Streaming
Call<ResponseBody> getData();
}
Call<ResponseBody> call = service.getData();
try {
InputStream in = call.execute().body().byteStream();
(...)
} catch (IOException e) {...}
这篇关于在 Retrofit 2 中支持 @Streaming的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文