下面的代码总是给出 I/O 异常,而我在浏览器中检查了它的工作情况,并且我在 Android Manifest 文件中给出了 Internet 权限。我从点击按钮上这样调用
CheckMetaData cmd = new CheckMetaData();
cmd.execute(url);
---------class def ---
private class CheckMetaData extends AsyncTask<String,Integer,InputStream> {
protected InputStream doInBackground(String... params) {
String url=params[0];
DefaultHttpClient client = new DefaultHttpClient();
HttpGet getRequest = new HttpGet(url);
try {
HttpResponse getResponse = client.execute(getRequest);
final int statusCode = getResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
Log.w(getClass().getSimpleName(),
"Error " + statusCode + " for URL " + url);
return null;
}
HttpEntity getResponseEntity = getResponse.getEntity();
return getResponseEntity.getContent();
}
catch (IOException e) {
getRequest.abort();
Log.w(getClass().getSimpleName(), "Error for URL " + url, e);
}
return null;
}