1緣由:
最近做一個上傳圖片的需求悯森,發(fā)現(xiàn)用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之后可以了。只是找到解決辦法了沒有找到為什么 是這樣冤今。如果有大佬看源碼找到原因可以 告知一下小弟