如何使用androidasynchttp:1.4.7在httppost设置超时



我正试图使用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) {
                ...
            }
         }

尝试添加此覆盖:

@Override
public void onFailure(int statusCode, Header[] headers, java.lang.Throwable throwable, org.json.JSONObject response) {
    Toast.makeText(getBaseContext(), "Error", Toast.LENGTH_SHORT).show();
    ....
}

还有一个你可以覆盖,但我认为你不需要它,但以防万一:

@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            super.onFailure(statusCode, headers, responseString, throwable);
            ....
}

小心你的成功,也许你需要在签名中添加一个带有JSONObject的。

相关内容

  • 没有找到相关文章

最新更新