You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Tretonio Tretis <tr...@gmail.com> on 2015/11/06 13:52:20 UTC

AsynchttpClient, using Accept-Enconding, As unpack a compressed return ?

As unpack a compressed return ?
Thanks


    final CountDownLatch latch2 = new CountDownLatch(1);
    final HttpPost request3 = new HttpPost("https://...");

         request3.setHeader("Accept-Encoding" ,  "gzip,deflate");   //
<------- here

    HttpAsyncRequestProducer producer3 = HttpAsyncMethods.create(request3);

    AsyncCharConsumer<HttpResponse> consumer3 = new
AsyncCharConsumer<HttpResponse>() {

        HttpResponse response;

        @Override
        protected void onResponseReceived(final HttpResponse response) {
            this.response = response;
        }

        @Override
        protected void onCharReceived(final CharBuffer buf, final IOControl
ioctrl) throws IOException {
            // Do something useful
        }

        @Override
        protected void releaseResources() {
        }

        @Override
        protected HttpResponse buildResult(final HttpContext context) {
            return this.response;
        }

    };
    httpclient.execute(producer3, consumer3, new
FutureCallback<HttpResponse>() {

        public void completed(final HttpResponse response3) {
            latch2.countDown();
            System.out.println(request2.getRequestLine() + "->" +
response3.getStatusLine());
        }

        public void failed(final Exception ex) {
            latch2.countDown();
            System.out.println(request2.getRequestLine() + "->" + ex);
        }

        public void cancelled() {
            latch2.countDown();
            System.out.println(request2.getRequestLine() + " cancelled");
        }

    });
    latch2.await();