【发布时间】:2015-06-26 14:23:36
【问题描述】:
我正在尝试使用 android-async-http:1.4.7 在 http post 设置超时来管理服务器,但设置 httpClient.setTimeout(1000) 它不起作用并且 onFailure 回调没有捕获异常. 这是我的代码
AsyncHttpClient httpClient = new AsyncHttpClient();
RequestParams requestParams = new RequestParams();
String s= sharedPrefs.getString("type_nn", "VGG");
requestParams.put("network", s);
if (destination== null) {
destination = new File(path);
}
requestParams.put("file", destination);
httpClient.setTimeout(1000);
httpClient.post("http://url", requestParams, new JsonHttpResponseHandler() {
@Override
public void onFailure(int statusCode, Header[] headers, java.lang.Throwable throwable, org.json.JSONArray response) {
Toast.makeText(activity, "Error", Toast.LENGTH_SHORT).show();
progressChargePhoto.setVisibility(View.GONE);
}
@Override
public void onSuccess(int statusCode, Header[] headers, org.json.JSONArray response) {
...
}
}
【问题讨论】:
标签: android timeout http-post android-async-http