如何在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;
}