1

I'm send a post request using Android async http and it seems that the response is null. I think it's because onSuccess of AsyncHttpResponseHandler doesn't get called. Here is my post request:

final String response[] = new String[1];
PersistentCookieStore myCookieStore = new PersistentCookieStore(act);
client.setCookieStore(myCookieStore);
RequestParams params = new RequestParams();
params.put("user_id", username);
params.put("password", password);
//other params
client.post(url, params, new AsyncHttpResponseHandler() {
    @Override
     public void onSuccess(int res, Header[] headers, byte[] body ) {
        //Logs don't get called
        Log.i("test", ""+res);
        Log.i("test", new String(body));
            response[0] = ""+ res;
            response[1] = new String(body);
    }
});
return response;

EDIT: After adding onFailure and printing the stack, I get this:

org.apache.http.client.HttpResponseException: Internal Server Error
12-29 13:42:12.450    2359-2386/com.sblive.aufschoolbliz W/System.err﹕ at com.loopj.android.http.AsyncHttpResponseHandler.sendResponseMessage(AsyncHttpResponseHandler.java:440)
12-29 13:42:12.450    2359-2386/com.sblive.aufschoolbliz W/System.err﹕ at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:78)
12-29 13:42:12.454    2359-2386/com.sblive.aufschoolbliz W/System.err﹕ at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:91)
12-29 13:42:12.454    2359-2386/com.sblive.aufschoolbliz W/System.err﹕ at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:54)
12-29 13:42:12.458    2359-2386/com.sblive.aufschoolbliz W/System.err﹕ at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
12-29 13:42:12.458    2359-2386/com.sblive.aufschoolbliz W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-29 13:42:12.458    2359-2386/com.sblive.aufschoolbliz W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-29 13:42:12.462    2359-2386/com.sblive.aufschoolbliz W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-29 13:42:12.462    2359-2386/com.sblive.aufschoolbliz W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
dgzz
  • 2,929
  • 6
  • 34
  • 56
  • 1
    Internal Server Error usually refers to an error at the server side. That can be caused because you sent an invalid request but still it should be diagnosed at the server side. Also your function is returning `response` before it's ready (and the `onSuccess()` callback is overwriting beyond the bounds of the response array). – laalto Dec 29 '13 at 13:49
  • yes, I got an array out of bounds after fixing the error.. but isn't it my response can hold 2 elements? – dgzz Dec 29 '13 at 13:57
  • `new String[1]` allocates space for one element only. – laalto Dec 29 '13 at 14:01

1 Answers1

3

Its actually http error 500 (internal server error). This problem is caused server side not client side. Please to try get the response code it will 500. Ultimately it should be handled at server side not client.

Sush
  • 3,864
  • 2
  • 17
  • 35