我正在使用这种方法从远程服务器获取 xml 文件,我使用另一个解析器类对其进行解析,并且解析成功。但是,当我Log.d("get xml", xml)
用来检查 xml 文件的内容时,它只显示<?xml version="1.0" standalone="no"?>
在 logCat 中。为什么?
public String getXmlFromUrl(String url) {
String xml = null;
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
if(httpPost != null){
Log.d("httpPost", "httpPost not null");
}
HttpResponse httpResponse = httpClient.execute(httpPost);
if(httpResponse != null){
Log.d("httpResponse", "httpResponse not null");
}
HttpEntity httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// return XML
Log.d("get xml", xml);
if(xml!=null){
Log.d("get http client", "get http client not null");
}
return xml;
}