2012-12-16 39 views
0

我正在使用此方法从远程服务器获取xml文件,我使用另一个解析器类来解析它,并且它已成功解析。但是,当我使用Log.d("get xml", xml)来检查xml文件的内容时,它只在logCat中显示<?xml version="1.0" standalone="no"?>。为什么?为什么我只需要获取<?xml version =“1.0”standalone =“no”?>何时请求一个xml文件? Android

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

回答

0

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

因此,通过在调试模式下应用断点来检查此问题。可能对你有帮助。

相关问题