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;
}
youssef1700
  • 109
  • 11

1 Answers1

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

Community
  • 1
  • 1
Rohit Arya
  • 6,751
  • 1
  • 26
  • 40