如何从网站获取文字到字符串?

时间:2013-03-14 19:12:00

标签: java android network-programming

如何在Android上将this URL的XML转换为String?我试图用教程来做,但没办法成功。这是我的代码:

public String getXmlFromUrl(String url) {
    String text = "";
    try {
        HttpGet get = new HttpGet(url); 
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(get);
        InputStream inputStream = response.getEntity().getContent();
        String line = "";
        BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream));
        while ((line = rd.readLine()) != null) {
            text += line; 
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return text;
}

0 个答案:

没有答案