我正在使用 Android 异步 http 发送一个发布请求,似乎响应为空。我认为这是因为没有调用 AsyncHttpResponseHandler 的 onSuccess 。这是我的发帖请求:
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;
编辑: 添加 onFailure 并打印堆栈后,我得到了这个:
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.
关于Android 异步 http 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20825582/