Search code examples
androidjsonandroid-networking

Error after submitting JSON data through POST


I'm trying to send data through POST to a web server.

Here is the code I'm using to perform the network call:

HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);
HttpPost post = new HttpPost(url);
StringEntity se = new StringEntity(json.toString());
se.setContentEncoding("UTF-8");
se.setContentType("application/json");
post.setEntity(se); 
HttpResponse response = client.execute(post);

I've verified using jsonlint that json.toString() returns a valid JSON.

I'm getting this error message as a response:

11-29 11:03:53.080: I/Storefront(1470): Response = <HTML><HEAD><TITLE>Service Unavailable</TITLE></HEAD><BODY><H1>Service Unavailable - Zero size object</H1>The server is temporarily unable to service your request.  Please try againlater.<P>Reference&#32;&#35;15&#46;163431d0&#46;1322593433&#46;2b040d2c</BODY></HTML>

The "Zero size object" message makes me think that the JSON data is not being sent properly.


Solution

  • Because you are receiving a valid response, it is probably an issue with how you are using the server. Make sure you are using the correct URL and sending the data in the expected manner.