简体   繁体   中英

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. 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. 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. Logging every line separately obtained the desired full response!.

So check this by applying breakpoint in debug mode. Might its help to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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