Synchronous GET Request

ANRequest request = AndroidNetworking.get(url)
        .addPathParameter("pageNumber", "0")
        .addQueryParameter("limit", "3")
        .build();
        
ANResponse<List<User>> response = request.executeForObjectList(User.class);

if (response.isSuccess()) {
    List<User> users = response.getResult();
    Log.d(TAG, "userList size : " + users.size());
    for (User user : users) {
        Log.d(TAG, "id : " + user.id);
        Log.d(TAG, "firstname : " + user.firstname);
        Log.d(TAG, "lastname : " + user.lastname);
    }
    Response okHttpResponse = response.getOkHttpResponse();
    Log.d(TAG, "headers : " + okHttpResponse.headers().toString());
} else {
    ANError error = response.getError();
    // Handle Error
}              

Synchronous POST Request

ANRequest request = AndroidNetworking.post("https://fierce-cove-29863.herokuapp.com/createAnUser")
                 .addBodyParameter("firstname", "Amit")
                 .addBodyParameter("lastname", "Shekhar")
                 .build();
        
ANResponse<JSONObject> response = request.executeForJSONObject();

if (response.isSuccess()) {
    JSONObject jsonObject = response.getResult();
    Log.d(TAG, "response : " + jsonObject.toString());
    Response okHttpResponse = response.getOkHttpResponse();
    Log.d(TAG, "headers : " + okHttpResponse.headers().toString());
} else {
    ANError error = response.getError();
    // Handle Error
}               

Synchronous Download Request

ANRequest request = AndroidNetworking
                    .download(url, Utils.getRootDirPath(getApplicationContext()), "file1.zip")
                    .build()
                    .setDownloadProgressListener(new DownloadProgressListener() {
                        @Override
                        public void onProgress(long bytesDownloaded, long totalBytes) {

                        }
                    });
                        
ANResponse<String> response = request.executeForDownload();

if (response.isSuccess()) {
    Response okHttpResponse = response.getOkHttpResponse();
    Log.d(TAG, "headers : " + okHttpResponse.headers().toString());
} else {
    ANError error = response.getError();
    // Handle Error
}          

Synchronous Upload Request

ANRequest request = AndroidNetworking.upload(url)
                 .addMultipartFile("image",file)    
                 .addMultipartParameter("key","value")
                 .setUploadProgressListener(new UploadProgressListener() {
                    @Override
                    public void onProgress(long bytesUploaded, long totalBytes) {
                      // do anything with progress 
                    }
                  })
                 .build();
        
ANResponse<JSONObject> response = request.executeForJSONObject();

if (response.isSuccess()) {
    JSONObject jsonObject = response.getResult();
    Log.d(TAG, "response : " + jsonObject.toString());
    Response okHttpResponse = response.getOkHttpResponse();
    Log.d(TAG, "headers : " + okHttpResponse.headers().toString());
} else {
    ANError error = response.getError();
    // Handle Error
}