我使用这个代码,以获得从给定的URL的RSS文件:的xml文件没有收到properlly
// get the xml file from the given url in a string format
public String getXmlFromUrl(String url)
{
String xml = null;
try
{
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
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
return xml;
}
这是获取XML文件的文本代码:
String yahoo_url = "http://feeds.finance.yahoo.com/rss/2.0/headline?s=intc®ion=US&lang=en-US";
parser = new XMLParser();
String text = parser.getXmlFromUrl(yahoo_url);
System.out.println(text);
而不是给我整个文件,我只得到两行:
"?xml version="1.0" encoding="utf-8"?
rss version="2.0"><channel/></rss?"
可能是什么问题?
谢谢
顺便说一下,你需要的,如果ClientProtocolException抛出消耗的实体,您可以通过'EntityUtils.consumes做到这一点(实体)' – 2012-07-12 20:16:51