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)
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top