0

Am trying to parsing a url "http://api.androidhive.info/contacts/" using AsyncHttpClient , after onStart() it is going to onFailure(), its not going to onSuccess() method and giving the result.

I try the same url by using normal AsyncTask , there after doInBckground(), it is going to onPostExecute() and getting the result.

in dependencies add

compile 'com.loopj.android:android-async-http:1.4.9'

and I import

import com.loopj.android.http.*;
import cz.msebera.android.httpclient.Header;

The code for parsing is

AsyncHttpClient client = new AsyncHttpClient();
            client.get("http://api.androidhive.info/contacts/", new AsyncHttpResponseHandler() {

                @Override
                public void onStart() {
                    // called before request is started
                    Toast.makeText(MainActivity.this,"on Start ",Toast.LENGTH_LONG).show();
                }

                @Override
                public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                    Toast.makeText(MainActivity.this,"onSuccess ",Toast.LENGTH_LONG).show();
                    Log.e("Tag ","success ");
                }


                @Override
                public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
                    // called when response HTTP status is "4XX" (eg. 401, 403, 404)
                    Toast.makeText(MainActivity.this,"onFailure ",Toast.LENGTH_LONG).show();
                }

                @Override
                public void onRetry(int retryNo) {
                    // called when request is retried
                }
            });

In Manifest I given the permission for INTERNET

Can any one please help for finding the mistake. Thanks in advance :)

Binil Surendran
  • 2,524
  • 6
  • 35
  • 58
  • Since the response is in JSON i would suggest using the recommended usage for the library - http://loopj.com/android-async-http/#recommended-usage-make-a-static-http-client. Also if you could log the `byte[] errorResponse` that you get in `onFailure` that will help. – Narayan Acharya Nov 25 '15 at 07:03
  • please provide what are the value coming to this variable on debugging (int statusCode, Header[] headers, byte[] errorResponse, Throwable e) – Askarc Ali Nov 25 '15 at 07:24

0 Answers0