我正在使用此代码从给定的 url 获取 rss 文件:
// 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?"
可能是什么问题?
谢谢