【问题标题】:Android Okhttp hides content encoding : gzip in the headerAndroid Okhttp 隐藏内容编码:标头中的 gzip
【发布时间】:2020-05-19 14:40:37
【问题描述】:

从 okhttp 的官方文档中,它声明它处理透明的 gzip 过程。但我的疑问是在我的标题中我看不到内容标题,我尝试从它给出的响应中检索标题content-encoding null。但我没有为编码添加任何额外的标头。 我通过RestClient 尝试了相同的请求,我可以看到标题content-encoding: gzip

fun getOkHttpClient(myInterceptor: MyInterceptor): OkHttpClient {
    val okHttpClientBuilder = OkHttpClient.Builder()
            .connectTimeout(10, TimeUnit.SECONDS)
            .readTimeout(60, TimeUnit.SECONDS)
            .writeTimeout(60, TimeUnit.SECONDS)
            .addInterceptor(myInterceptor)
    return okHttpClientBuilder.build()
}

谁能建议我可能是什么问题?

【问题讨论】:

    标签: android kotlin retrofit2 okhttp


    【解决方案1】:

    这是一个功能:

    如果使用透明压缩,OkHttp 将丢弃相应的响应头 Content-EncodingContent-Length,因为它们不适用于解压后的响应体。

    source

    【讨论】:

    • 另外,您可以使用Response.networkResponse.request 查看通过网络发送的内容。
    猜你喜欢
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    • 2016-11-10
    • 2020-01-18
    • 1970-01-01
    • 2015-01-17
    • 1970-01-01
    • 2014-03-19
    相关资源
    最近更新 更多