Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8205367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:12:46+00:00 2026-06-07T08:12:46+00:00

I am sending a JSONObject to my Webserver from an Android client using the

  • 0

I am sending a JSONObject to my Webserver from an Android client using the code from this example. Reproducing code here

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

int TIMEOUT_MILLISEC = 10000;  // = 10 seconds
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
HttpClient client = new DefaultHttpClient(httpParams);

HttpPost request = new HttpPost(serverUrl);
request.setEntity(new ByteArrayEntity(
    postMessage.toString().getBytes("UTF8")));
HttpResponse response = client.execute(request);

My Question

How to do best compression on JSONObject before sending it to server and how to decompress it on Server (I am using Java Servlets)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:12:48+00:00Added an answer on June 7, 2026 at 8:12 am

    According to this http://android-developers.blogspot.com/2011/09/androids-http-clients.html If you are using Gingerbread or later HttpURLConnection automatically adds gzip compression:

    In Gingerbread, we added transparent response compression.
    HttpURLConnection will automatically add this header to outgoing
    requests, and handle the corresponding response:

    Accept-Encoding: gzip

    Your webserver would then need to handle gzip compression.

    Edit:
    Serve Gzipped content with Java Servlets

    Edit 2:
    Gzip compression using DefaultHttpClient Enabling GZip compression with HttpClient

    private static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding";
    private static final String ENCODING_GZIP = "gzip";
    
    final DefaultHttpClient client = new DefaultHttpClient(manager, parameters);
    
    client.addRequestInterceptor(new HttpRequestInterceptor() {
      public void process(HttpRequest request, HttpContext context) {
        // Add header to accept gzip content
        if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) {
          request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
        }
      }
    });
    
    client.addResponseInterceptor(new HttpResponseInterceptor() {
      public void process(HttpResponse response, HttpContext context) {
        // Inflate any responses compressed with gzip
        final HttpEntity entity = response.getEntity();
        final Header encoding = entity.getContentEncoding();
        if (encoding != null) {
          for (HeaderElement element : encoding.getElements()) {
            if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) {
              response.setEntity(new InflatingEntity(response.getEntity()));
              break;
            }
          }
        }
      }
    });
    

    Edit 3:
    Here is another Stackoverflow question regarding the gzipping of post contents GZip POST request with HTTPClient in Java. You will need to manually gzip the data before posting it, since the normal http/gzip operation is the server sending gzipped content to the client.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sending XML from C# Server and receiving it it in Android Java client This
This question is extension to the question here . I am using the code
Sending Email in Android using JavaMail API without using the default/built-in app I'm trying
I am sending a string down from a websockets server to my client that
I am sending a json object from java to php. I am using gson
i am trying to send a json string from my android client to my
Javascript/jQuery newbie here. My webserver is sending the contents of a directory tree as
I have written a code in android as as well as in php..while sending
When sending json data to client side, I get the data like this. {Data:{rows:[{id:1,cell:[1,amila,amila,False]},{id:2,cell:[2,rakhitha,rakhitha,False]},{id:3,cell:[3,Chathura,Chathura,False]},{id:4,cell:[4,Geethaga,Geethaga,False]}]},JsonRequestBehavior:0}
I am trying to receive a json object back from php after sending data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.