2012-12-16 43 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中的輸出。記錄每一行分別獲得所需的完整響應!

因此,通過在調試模式下應用斷點來檢查此問題。可能對你有幫助。

相關問題