Retrofit and OkHttp gzip decode

前端 未结 1 1573
我在风中等你
我在风中等你 2020-12-09 02:18

The REST service I want to consume answers as a gzipped encoded JSON. It provides the Content-Encoding: gzip, but my OkHttp does not encode it to readable text,

相关标签:
1条回答
  • 2020-12-09 03:09

    Replace this:

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

    With this:

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

    When you provide your own Accept-Encoding header you’re instructing OkHttp that you want to do your own decompression. By omitting it, OkHttp will take care of both adding the header and the decompression.

    0 讨论(0)
提交回复
热议问题