繁体   English   中英

为什么我只得到 <?xml version=“1.0” standalone=“no”?> 什么时候要求xml文件? 安卓系统

[英]Why am I only getting <?xml version=“1.0” standalone=“no”?> when request for a xml file? Android

我正在使用此方法从远程服务器获取xml文件,我使用另一个解析器类对其进行解析,然后成功解析了该文件。 但是,当我使用Log.d("get xml", xml)检查xml文件的内容时,它仅在logCat中显示<?xml version="1.0" standalone="no"?> 为什么?

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;
}

我认为问题不在于请求,而是LogCat中的输出。 分别记录每行可获得所需的完整响应!

因此,通过在调试模式下应用断点来进行检查。 可能会为您提供帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM