OkHttp 对请求启用/禁用 gzip 压缩 [英] OkHttp enable/disable gzip compression on requests

查看:151
本文介绍了OkHttp 对请求启用/禁用 gzip 压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Retrofit 来管理我的请求,并希望进行一些测试以检查使用或不使用 gzip 的请求大小.

I'm using Retrofit to manage my requests and want to make some tests to check de request size using or not using gzip.

默认情况下,OkHttp 对请求执行 gzip 压缩,或者必须使用 拦截器?

By default does OkHttp performs gzip compression to requests or it must be implemented with an interceptor?

我已添加

@Headers({
        "Accept-Encoding: gzip, deflate",
        "Content-Encoding: gzip"
})

或:

@Headers({
        "Content-Type: application/json;charset=utf-8",
        "Accept: application/json"
})

根据我的请求,没有看到请求长度有任何变化.

to my requests and did not see any change on the request length.

推荐答案

OkHttp 将对响应体执行透明 gzip,除非您使用此标头禁用该功能:

OkHttp will do transparent gzip on response bodies unless you disable the feature with this header:

Accept-Encoding: identity

这篇关于OkHttp 对请求启用/禁用 gzip 压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆