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 :)