Java 使用传输编码改进客户端和响应:分块
我正在开发一个Android示例应用程序,从中获取电影列表 其余服务为:Java 使用传输编码改进客户端和响应:分块,java,android,http,retrofit2,transfer-encoding,Java,Android,Http,Retrofit2,Transfer Encoding,我正在开发一个Android示例应用程序,从中获取电影列表 其余服务为: http://www.omdbapi.com/?s=star&apikey=d497e644 我正在使用改型来编写客户端 public interface OmdbApi { @Streaming @GET("./") @Headers({"Cache-control: no-cache"}) Call<Search> search(@Query("s") String
http://www.omdbapi.com/?s=star&apikey=d497e644
我正在使用改型来编写客户端
public interface OmdbApi {
@Streaming
@GET("./")
@Headers({"Cache-control: no-cache"})
Call<Search> search(@Query("s") String search, @Query("apikey") String apiKey);
@Streaming
@GET("./")
@Headers({"Cache-control: no-cache"})
Call<FilmDetail> getFilm(@Query("i") String uid, @Query("apikey") String apiKey);
}
以及以下错误:
java.net.ProtocolException: unexpected end of stream
at okhttp3.internal.http1.Http1Codec$ChunkedSource.read(Http1Codec.java:455)
at okio.RealBufferedSource.read(RealBufferedSource.java:47)
okio.RealBufferedSource.exhausted(RealBufferedSource.java:57)
okio.InflaterSource.refill(InflaterSource.java:102)
okio.InflaterSource.read(InflaterSource.java:62)
okio.GzipSource.read(GzipSource.java:80)
okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:237)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:91)
com.abubusoft.filmfinder.service.repository.FilmRepository.lambda$findFilm$0$FilmRepository(FilmRepository.java:18)
com.abubusoft.filmfinder.service.repository.FilmRepository$$Lambda$0.run(Unknown Source:20)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
经过一点调查,我发现问题在于响应具有传输编码:chunked
。我如何解决这个问题
谢谢。经过进一步调查:
- 我删除了
注释。。它们没有用@Streaming
- 我所做的测试是在防火墙后面的PC上的模拟器上进行的
在很多年前就遇到了一些问题,但现在分块传输完全得到了管理OkHttp
- 在同一台计算机上,在浏览器中调用相同的URL不会出现任何问题
java.net.ProtocolException: unexpected end of stream
at okhttp3.internal.http1.Http1Codec$ChunkedSource.read(Http1Codec.java:455)
at okio.RealBufferedSource.read(RealBufferedSource.java:47)
okio.RealBufferedSource.exhausted(RealBufferedSource.java:57)
okio.InflaterSource.refill(InflaterSource.java:102)
okio.InflaterSource.read(InflaterSource.java:62)
okio.GzipSource.read(GzipSource.java:80)
okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:237)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:91)
com.abubusoft.filmfinder.service.repository.FilmRepository.lambda$findFilm$0$FilmRepository(FilmRepository.java:18)
com.abubusoft.filmfinder.service.repository.FilmRepository$$Lambda$0.run(Unknown Source:20)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)