关于http协议练习,取不到数据

羊鑫 发布于 2013/08/05 15:29
阅读 177
收藏 0

    小弟自学android,在练习http协议跑程序的时候没有数据返回,如下代码:

//生成一个请求对象
HttpGet httpGet = new HttpGet("http://www.baidu.com");
//生成一个http客服端对象
HttpClient httpClient = new DefaultHttpClient();
//使用http客服端发送请求对象
InputStream inputStream = null;
try {
httpResponse = httpClient.execute(httpGet);
httpEntity = httpResponse.getEntity();
inputStream = httpEntity.getContent();
BufferedReader bfr = new BufferedReader(new InputStreamReader(inputStream));
String result = "";
String line = "";
while((line = bfr.readLine()) != null){
result += line;
}
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}

网络注册:<uses-permission android:name="android.permission.INTERNET" />

请问这是怎么回事呀。

加载中
返回顶部
顶部