1

I'm using ASP Web API web service which is hosted on SmarterAsp.net to get data in Json format to use them in my android application, when I use Wifi everything works fine and the Json is received correctly but when I use mobile data I get com.google.gson.JsonSyntaxException while parsing the Json received, I checked the received Json string with the debugger and it was malformed and here is what i received :

��������������RMo�@�+՞)��Sڦ9TjeU�)�aX�x\��Ah"�{b�����̾y3OL�G�Y�İ�u²"���r'��J V�@�����(��� ���(N9*4MĜ���Fר��m+ ���:�7[�/$3��z����c�%q*Ha�OA|�x~������G�8���"?,�4���(��y���N��j�L%���?B �?S8�lp���(G�rgH�����P�b9����+5��<�n����w_i�G-,��_؋��uz�K;��|�i������� ��|6s����V[J�<�%3� � �X�������

And here is the method I'm using in android to send and receive data from the ASP Web API web service :

public String PostObject(String url, Object obj) throws IOException {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url);
    StringEntity stringEntity = new StringEntity(new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create().toJson(obj));
    httpPost.setEntity(stringEntity);
    httpPost.setHeader("Accept", "application/json");
    httpPost.setHeader("Content-type", "application/json");
    httpPost.setHeader("Accept-Encoding", "gzip");
    HttpResponse httpResponse = client.execute(httpPost);
    HttpEntity httpEntity = httpResponse.getEntity();
    String rep = EntityUtils.toString(httpEntity);
    return rep;
}

1 Answer 1

2

It is not malformed. You are accepting gzip compressed data by declaring ("Accept-Encoding", "gzip") in the header.

You can either remove the compression or decompress the data and then use it.

On how to decompress

Sign up to request clarification or add additional context in comments.

2 Comments

but can you explain why the data are compressed only when using mobile data ?
It's behavior should be same in all case. Are you sure you are calling same method in case of both Wifi and mobile data?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.