代码之家  ›  专栏  ›  技术社区  ›  UmAnusorn

在Android上的okhttp上出现错误,应为null,但却是okhttp3。内部.http1.http1代码

  •  1
  • UmAnusorn  · 技术社区  · 6 年前

    (我们使用okhttp和 ApolloGraphQL

    Fatal Exception: java.lang.IllegalStateException
    expected null but was okhttp3.internal.http1.Http1Codec
    
    okhttp3.internal.connection.StreamAllocation.streamFinished (StreamAllocation.java:304)
    okhttp3.internal.http1.Http1Codec$AbstractSource.endOfInput (Http1Codec.java:386)
    okhttp3.internal.http1.Http1Codec$FixedLengthSource.read (Http1Codec.java:416)
    okio.RealBufferedSource.request (RealBufferedSource.java:68)
    okhttp3.logging.HttpLoggingInterceptor.intercept (HttpLoggingInterceptor.java:241)
    okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:147)
    okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:121)
    okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java:200)
    okhttp3.RealCall$AsyncCall.execute (RealCall.java:147)
    okhttp3.internal.NamedRunnable.run (NamedRunnable.java:32)
    
    2 回复  |  直到 6 年前
        1
  •  0
  •   UmAnusorn    6 年前

    ResponseBody responseBodyCopy = response.peekBody(Long.MAX_VALUE);
    responseBodyCopy.string();
    
        2
  •  0
  •   UmAnusorn    6 年前

    所以在我们得到字符串之前,这个值可能就消失了

    response.errorBody().toString

    我们最好使用

    ResponseBody errorBody = Objects.requireNonNull(response.errorBody());
    String errorString = errorBody.toString();
    onFailure(new ApiError(response.code(), errorString));