I am trying to post a json object through android ion library on a computer in my local network with the following code :
String url = "http://192.168.1.23/ws/svn/branches/application/public/connectMobile";
try {
JsonObject json = new JsonObject();
json.addProperty("email", email.getText().toString());
json.addProperty("psw", password.getText().toString());
Log.i("json envoyé",json.toString());
Ion.with(context)
.load("POST",url)
.addHeader("Content-Type", "application/json")
.setLogging("ion-geny", Log.DEBUG)
.setJsonObjectBody(json)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
if (result != null)
{
Log.i("result",result.toString());
}
else
{
Log.i("result","null");
}
if (e != null)
{
Log.i("error",e.toString());
}
else
{
Log.i("error","null");
}
}
});
} catch (Exception ex) {
ex.printStackTrace();
Log.i("except", ex.toString());
}
The debug gives this :
09-27 12:19:43.302 3309-3309/com.bewizme.bewizmeloginsample I/email﹕ f@f.com 09-27 12:19:43.302 3309-3309/com.bewizme.bewizmeloginsample I/Password﹕ f 09-27 12:19:43.362 3309-3309/com.bewizme.bewizmeloginsample I/connected﹕ connected true 09-27 12:19:43.402 3309-3309/com.bewizme.bewizmeloginsample D/dalvikvm﹕ GC_FOR_ALLOC freed 142K, 7% free 2917K/3116K, paused 15ms, total 18ms 09-27 12:19:43.482 3309-3309/com.bewizme.bewizmeloginsample I/json envoyé﹕ {"email":"f@f.com","psw":"f"} 09-27 12:19:43.602 3309-3309/com.bewizme.bewizmeloginsample D/dalvikvm﹕ GC_FOR_ALLOC freed 154K, 6% free 3275K/3480K, paused 14ms, total 15ms 09-27 12:19:43.622 3309-3309/com.bewizme.bewizmeloginsample D/ion-geny﹕ (0 ms) http://192.168.1.23/ws/svn/branches/application/public/connectMobile: preparing request 09-27 12:19:43.632 3309-3309/com.bewizme.bewizmeloginsample I/ion-geny﹕ (0 ms) http://192.168.1.23/ws/svn/branches/application/public/connectMobile: Using loader: com.koushikdutta.ion.loader.HttpLoader@b20a3808 09-27 12:19:43.652 3309-3331/com.bewizme.bewizmeloginsample D/ion-geny﹕ (0 ms) http://192.168.1.23/ws/svn/branches/application/public/connectMobile: Executing request. 09-27 12:19:44.862 3309-3331/com.bewizme.bewizmeloginsample D/ion-geny﹕ (1212 ms) http://192.168.1.23/ws/svn/branches/application/public/connectMobile: Response is not cacheable 09-27 12:19:44.902 3309-3331/com.bewizme.bewizmeloginsample D/ion-geny﹕ (1249 ms) http://192.168.1.23/ws/svn/branches/application/public/connectMobile: Connection successful 09-27 12:19:45.002 3309-3331/com.bewizme.bewizmeloginsample D/dalvikvm﹕ GC_FOR_ALLOC freed 263K, 9% free 3462K/3788K, paused 61ms, total 61ms 09-27 12:19:45.052 3309-3309/com.bewizme.bewizmeloginsample I/result﹕ null 09-27 12:19:45.052 3309-3309/com.bewizme.bewizmeloginsample I/error﹕ com.google.gson.JsonParseException: unable to parse json
I suspect that the parse error is due to the fact that nothing is returned.
Moreover, on my server, I wrote a piece of code to check what's coming in, and I receive nothing on the server from my sample but when trying with RESTEASY with firefox sending the same, the post is correctly sent my server receives the post and a response is sent back.
Any idea ? I can't figure out what's wrong...