我正在使用异步 Http 客户端工具,可以在此处找到:http://loopj.com/android-async-http/。除了大约每十次请求中的一次会出现无限进度对话框外,它都很好用。我认为这意味着由于某种原因没有任何响应被返回,因为我已经编写了代码在 onSuccess 和 onFailure 中关闭对话框,所以我有点困惑它为什么会发生。
下面是设置请求的代码:
下面是设置请求的代码:
public static void post(String token,String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
Log.i(token,"token");
client.addHeader("token", token);
client.setTimeout(3000);
client.post(url, params, responseHandler);
}
这里是我重写onSuccess和onFailure的地方:
@Override
public void onFailure(Throwable arg0, String arg1) {
// TODO Auto-generated method stub
super.onFailure(arg0, arg1);
pdialog.dismiss();
Log.i("failed to login", arg1.toString());
Toast.makeText(getActivity(), arg1.toString() , Toast.LENGTH_LONG).show();
}
@Override
public void onSuccess(final JSONObject json) {
pdialog.dismiss();
}