从Android获取Web服务的数据

时间:2011-10-06 09:21:21

标签: android web-services bufferedreader

    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet();
    request.setURI(new URI(address));
    HttpResponse response = client.execute(request);
    BufferedReader in = new BufferedReader(new 
InputStreamReader(response.getEntity().getContent()));

当我检索这样的信息时,bufferedreader in只包含一个带有整个文本的长行。它不会将中断数据划分为多行。结果,只有前3个字符合适用于该行,其余的则被丢失。我该如何避免这个问题?

2 个答案:

答案 0 :(得分:1)

简单

URL url = new URI(address).toURL();
InputStream is = url.openStream();

答案 1 :(得分:0)

你试试这个吗?

String data = EntityUtils.toString(response.getEntity());