Mridang Agarwalla
Mridang Agarwalla

Reputation: 45088

Does HttpURLConnection support compression/decompression out of the box?

I'm using the HttpURLConnection to make some GET request and fetch pages. I'd like to request gzipped responses but I haven't found any information whether HttpURLConnection support Gzip.

Do i need to simply add the header Accept-Encoidng: gzip to the request or is there something else I need to do in order to handle gzipped responses?

Upvotes: 3

Views: 1749

Answers (1)

MadConan
MadConan

Reputation: 3767

No, the HttpURLConnection does not "handle" compression out of the box. It simply streams the request and response using HTTP. You will need to handle the response compression if it is utilized, which you can find out by checking the response header, for example

 Content-Encoding: gzip

The encoding type may be something other than gzip, too. Like you mentioned, you need to set your request header, stating you support compression.

Upvotes: 1

Related Questions