[英]Why am I only getting <?xml version=“1.0” standalone=“no”?> when request for a xml file? Android
I am using this method to get xml file from a remote server, I use another parser class to parse it, and it got parsed successfully. 我正在使用此方法从远程服务器获取xml文件,我使用另一个解析器类对其进行解析,然后成功解析了该文件。 However, when i use Log.d("get xml", xml)
to check the content of the xml file, it only shows <?xml version="1.0" standalone="no"?>
in logCat. 但是,当我使用Log.d("get xml", xml)
检查xml文件的内容时,它仅在logCat中显示<?xml version="1.0" standalone="no"?>
。 Why? 为什么?
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;
}
I think the problem wasn't the request but the output in the LogCat. 我认为问题不在于请求,而是LogCat中的输出。 Logging every line separately obtained the desired full response!. 分别记录每行可获得所需的完整响应!
So check this by applying breakpoint in debug mode. 因此,通过在调试模式下应用断点来进行检查。 Might its help to you. 可能会为您提供帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.