在 onStart()之后尝试使用 http://api.androidhive.info/contacts/ 解析网址“ SQL Fiddle ”时,它会 onFailure(),它不会去 onSuccess()方法并给出结果。
我使用普通的AsyncTask尝试相同的网址,在 doInBckground()之后,它会转到 onPostExecute()并获得结果。
在依赖项中添加
compile 'com.loopj.android:android-async-http:1.4.9'
我导入
import com.loopj.android.http.*;
import cz.msebera.android.httpclient.Header;
解析代码是
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
}
});
在Manifest中,我获得了INTERNET的许可
任何人都可以帮助找到错误。 在此先感谢:)