I am try to use android-async-http, but always onFailure, and from the log I can see the status code = 0. However, when I use the traditional way (org.apache.http.client.HttpClient), the status code = 200;
the code:
public class HttpTestActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_http_test);
testHttp();
testHttp2();
}
public void testHttp2() {
new Thread(new Runnable() {
@Override
public void run() {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://www.baidu.com");
try {
HttpResponse httpResponse = httpClient.execute(httpGet);
int statusCode = httpResponse.getStatusLine().getStatusCode();
Log.i("ws", "---->>22: status code: " + statusCode);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
public void testHttp() {
Log.i("ws", "---->>testHttp");
VStarRestClient.get("http://www.baidu.com", null, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
Log.i("ws", "---->>onSuccess :" + statusCode);
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
Log.i("ws", "---->>onFailure : " + statusCode);
}
});
}