kotlin 抛出java.net,协议异常:意外的流结束[重复]

wsewodh2  于 2023-02-16  发布在  Kotlin
关注(0)|答案(2)|浏览(257)
    • 此问题在此处已有答案**:

Okhttp java.net.ProtocolException: unexpected end of stream(4个答案)
2天前关闭。
我试图从我的服务器与Android 8(26奥利奥)获取数据,我得到以下错误:

java.net.ProtocolException: unexpected end of stream
    at 
okhttp3.internal.http1.Http1Codec$FixedLengthSource.read(Http1Codec.java:398)
    at okio.RealBufferedSource.read(RealBufferedSource.java:46)
    at okio.ForwardingSource.read(ForwardingSource.java:35)
    at 
retrofit2.OkHttpCall$ExceptionCatchingRequestBody$1.read(OkHttpCall.java:291)
    at okio.RealBufferedSource$1.read(RealBufferedSource.java:430)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:287)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:350)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:179)
    at java.io.InputStreamReader.read(InputStreamReader.java:184)
    at okhttp3.ResponseBody$BomAwareReader.read(ResponseBody.java:252)
    at com.google.gson.stream.JsonReader.fillBuffer(JsonReader.java:1287)
    at 
  com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1325)
    at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:482)
    at com.google.gson.stream.JsonReader.hasNext(JsonReader.java:414)
    at 
  com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read
 (Reflecti veTypeAdapterFactory.java:214)
     at 
 retrofit2.converter.gson.GsonResponseBodyConverter.convert
  (GsonResponseBodyConve rter.java:37)
    at 
 retrofit2.converter.gson.GsonResponseBodyConverter.convert
(GsonResponseBodyConve rter.java:25)
    at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:119)
    at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:218)
    at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:112)
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:153)
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
    at 
  java.util.concurrent.ThreadPoolExecutor.runWorker
 (ThreadPoolExecutor.java:1133)
    at 
  java.util.concurrent.ThreadPoolExecutor$Worker.run
   (ThreadPoolExecutor.java:607)
    at java.lang.Thread.run(Thread.java:761)

我使用的是Retrofit 2.3.0和OkHttp 3.9.0。奇怪的是,这个错误只发生在API 26奥利奥上,而不是以前的任何API上,我随机得到这个错误,有时是,有时不是。

qvk1mo1f

qvk1mo1f1#

在您的翻新电话中尝试使用此@Header("Connection","close")。它已为我解决了问题。

omqzjyyz

omqzjyyz2#

如果你的应用程序是在模拟器,尝试在您的移动的。这对我的工作。

相关问题