How to get respond (status) code from get request?

Hi I am using this library:

and I cant find how to get status code from GET request from example. I dont know if there is some documentation I am missing but anyways I would really appreciate if someone can tell me how to do that.

1 answer

  • answered 2018-02-13 01:10 shuwn yuan tee

    This is an example code found in the repo Fast-Android-Networking. This is a GET request which uses getAsJSONArray & specify a JSONArrayRequestListener to it.

    In JSONArrayRequestListener, when onResponse is called, most probably indicate HTTP status code is 200 OK. For any error condition, onError is called. You can get error code with error.getErrorCode().

    AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY)
        .addPathParameter("pageNumber", "0")
        .addQueryParameter("limit", "3")
        .getAsJSONArray(new JSONArrayRequestListener() {
            public void onResponse(JSONArray response) {
                Log.d(TAG, "onResponse array : " + response.toString());
            public void onError(ANError error) {
                if (error.getErrorCode() != 0) {
                    // received ANError from server
                    // error.getErrorCode() - the ANError code from server
                    // error.getErrorBody() - the ANError body from server
                    // error.getErrorDetail() - just a ANError detail
                    Log.d(TAG, "onError errorCode : " + error.getErrorCode());
                    Log.d(TAG, "onError errorBody : " + error.getErrorBody());
                    Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
                } else {
                    // error.getErrorDetail() : connectionError, parseError, requestCancelledError
                    Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());

    Hope this help, good luck!