0

POST 大型(17048 字节)API 请求时,我的 Android 应用程序开始失败,如下所示

2019-09-20 08:20:01.198 15645-15862/org.aaa.bbb.ccc.mycompany D/GraphqlNetworkControlle: mutation {"operationName":"myOperation","variables":{"uuids":["
2019-09-20 08:20:01.207 15645-15862/org.aaa.bbb.ccc.mycompany D/OkHttp: --> POST https://mycompany.com/graphql
2019-09-20 08:20:01.208 15645-15862/org.aaa.bbb.ccc.mycompany D/OkHttp: Content-Type: application/json
2019-09-20 08:20:01.208 15645-15862/org.aaa.bbb.ccc.mycompany D/OkHttp: Content-Length: 17048
2019-09-20 08:20:01.208 15645-15862/org.aaa.bbb.ccc.mycompany D/OkHttp: authorization: Bearer eyJrauYhjiknbgsdsRPS0VOIiwiYWxnIjoiRVMyNTYifQ.eyJzdWIiOiJk
2019-09-20 08:20:01.208 15645-15862/org.aaa.bbb.ccc.mycompany D/OkHttp: --> END POST
2019-09-20 08:20:01.213 15645-15862/org.aaa.bbb.ccc.mycompany D/OkHttp: <-- HTTP FAILED: java.io.InterruptedIOException: interrupted
2019-09-20 08:20:01.215 15645-15862/org.aaa.bbb.ccc.mycompany E/PendingMutationSO: processError()
    java.io.InterruptedIOException: interrupted
        at okio.Timeout.throwIfReached(Timeout.kt:98)
        at okio.OutputStreamSink.write(Okio.kt:53)
        at okio.AsyncTimeout$sink$1.write(AsyncTimeout.kt:106)
        at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.kt:181)
        at okio.RealBufferedSink.write(RealBufferedSink.kt:39)
        at okhttp3.internal.http2.Http2Writer.dataFrame(Http2Writer.kt:165)
        at okhttp3.internal.http2.Http2Writer.data(Http2Writer.kt:153)
        at okhttp3.internal.http2.Http2Connection.writeData(Http2Connection.kt:320)
        at okhttp3.internal.http2.Http2Stream$FramingSink.emitFrame(Http2Stream.kt:539)
        at okhttp3.internal.http2.Http2Stream$FramingSink.write(Http2Stream.kt:510)
        at okio.ForwardingSink.write(ForwardingSink.kt:29)
        at okhttp3.internal.connection.Exchange$RequestBodySink.write(Exchange.kt:222)
        at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.kt:181)
        at okio.RealBufferedSink.write(RealBufferedSink.kt:92)
        at okhttp3.RequestBody$Companion$toRequestBody$2.writeTo(RequestBody.kt:147)
        at retrofit2.RequestBuilder$ContentTypeOverridingRequestBody.writeTo(RequestBuilder.java:283)
        at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:59)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:37)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:82)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:84)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:71)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
        at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.kt:215)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)

17048 字节的请求是“太大”还是应该改造能够处理这个?

这是一个“后端”问题吗?

无论如何我可以在客户端解决这个问题吗?

我配置改造如下: -

internal val okHttpClient:OkHttpClient = configure()

    private fun configure(): OkHttpClient {

        val okHttpClientBuilder: OkHttpClient.Builder = OkHttpClient.Builder()
                .connectTimeout(OK_HTTP_CLIENT_TIMEOUT, TimeUnit.MILLISECONDS)
                .readTimeout(OK_HTTP_CLIENT_TIMEOUT, TimeUnit.MILLISECONDS)
                .writeTimeout(OK_HTTP_CLIENT_TIMEOUT, TimeUnit.SECONDS)
                .callTimeout(OK_HTTP_CLIENT_TIMEOUT, TimeUnit.MILLISECONDS)
                .followSslRedirects(true)
                .retryOnConnectionFailure(true)
                .followRedirects(true)

        return okHttpClientBuilder.build()
    }

    companion object {

        private const val OK_HTTP_CLIENT_TIMEOUT: Long = 60000

    }
4

0 回答 0