java - Problem gzipping HttpPost body using Apache Client 4.1.1 -
i need send httppost body gzipped, server accepts non gzipped data prefer gzipped, im trying convert existing workign code use gzip data set with
httpmethod.setentity(new urlencodedformentity(namevaluepairs));
ive tried sublclassing httpentitywrapper
static class gzipwrapper extends httpentitywrapper { public gzipwrapper(httpentity wrapped) { super(wrapped); } public void writeto(outputstream outstream) throws ioexception { gzipoutputstream gzip = new gzipoutputstream(outstream); super.writeto(gzip); } }
and changed
httpmethod.setentity(new gzipwrapper( new urlencodedformentity(namevaluepairs)));
and added
if (!httpmethod.containsheader("accept-encoding")) { httpmethod.addheader("accept-encoding", "gzip"); }
but request time outs think there must wrong gzipwrapper im not sure what.
on note looked @ http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/clientgzipcontentcompression.java. example. aside fact dont interceptors because difficult follow program flow doesnt make sense me because request header set tell server accept gzip data gzip encode data, unzips response.
(1) gzipwrapper implementation wrong. transforms entity content when writing out output stream still returns content-length of wrapped entity, causing server expect more input transmitted client.
(2) misunderstand purpose of accept-encoding
header
http://www.w3.org/protocols/rfc2616/rfc2616-sec14.html
(3) clientgzipcontentcompression sample correct. not compress outgoing request entity because not meant so. see point (2)
Comments
Post a Comment