What header should be used for sending GZIP compressed JSON from Android Client to Server?

前端 未结 3 1280
别跟我提以往
别跟我提以往 2020-12-14 08:03

This question is extension to the question here. I am using the code here reproduced below to GZIP compress a JSONObject.

String foo = \"value\         


        
相关标签:
3条回答
  • 2020-12-14 08:09

    This answer shows you that you need to set a header indicating that you are sending data compressed:

    HttpUriRequest request = new HttpGet(url);
    request.addHeader("Content-Encoding", "gzip");
    // ...
    httpClient.execute(request);
    

    The answer also shows how to deal with the incoming compressed data.

    0 讨论(0)
  • 2020-12-14 08:19

    To inform the server that you are sending gzip-encoded data, send the Content-Encoding header, not Accept-Encoding.

    0 讨论(0)
  • 2020-12-14 08:28
    • Content-Type:application/json - tells what type of content data in the http call
    • Content-Encoding: gzip - tells what compression being used.

    application/json or text/xml or other type can be compressed as gzip and sending to receiver and with Content-Type header only, receiver will identify the incoming data is of type json/xml/text and then convert back to object of type json/xml/text.

    With Content-Encoding header only receiver will identify the incoming data is getting gzip compressed. Then receiver required to decompress the incoming data and use it.

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