1缘由:
最近做一个上传图片的需求,发现用Fast-Android-Networking上传图片的时候一直报一个异常 java.net.ProtocolException: unexpected end of stream。
2.原因:
原因是设置打印log的拦截器的等级设置成body导致的就是
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel( HttpLoggingInterceptor.Level.BODY);
OkHttpClient okHttpClient = builder
.addInterceptor(loggingInterceptor)
.proxy( Proxy.NO_PROXY)
.build();
3.解决办法
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel( HttpLoggingInterceptor.Level.HEADERS);
OkHttpClient okHttpClient = builder
.addInterceptor(loggingInterceptor)
.proxy( Proxy.NO_PROXY)
.build();
然后我尝试把HttpLoggingInterceptor.Level.BODY 修改成HttpLoggingInterceptor.Level.HEADERS之后可以了。只是找到解决办法了没有找到为什么 是这样。如果有大佬看源码找到原因可以 告知一下小弟