Does the library Apache Commons HttpClient support Gzip? We wanted to use enable gzip compression on our Apache server to speed up the client/server communications (we have a php page that allows our Android application to sync files with the Server).
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
If your server is able to provide GZIPped content, with Apache Http client 4.1 all you need is to use
which is a subclass of
DefaultHttpClient
.This client will also add headers saying that it accepts GZIPped content.
Custom Protocol Interceptors may help as well.
Disclaimer: I haven't tried this yet.
It doesn't support it out of the box but you can transform entity of returned
HttpResponse
into uncompressed one by callingthen proceed with
entity.getContent
as always.Since 4.1, Apache HttpClients handles request and response compression.
ResponseContentEncoding
api doc here.Just use:
which uses:
If you want to check in library goto
HttpClientBuilder
it usesRequestAcceptEncoding
&ResponseContentEncoding
You can disable it through "disableContentCompression()"
Please make sure if you add any interceptor it can override that, use it carefully.
It has no support for this out-of-the-box, and it seems unlikely to be added to HttpClient 3.x (see rather bitchy JIRA issue here). You can, however, do it by adding custom request readers and manual request/response stream handling, layered on top of the basic library, but it's fiddly.
It seems you can do it with HttpClient 4, but not without some effort.
Pretty shoddy, if you ask me, this stuff really should be easier than it is.
Here is the sample scala code which uses java apache-http-client library