Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-HttpEntity返回“;“未找到资源”;页_Android_Xml_Http_Xml Parsing - Fatal编程技术网

Android-HttpEntity返回“;“未找到资源”;页

Android-HttpEntity返回“;“未找到资源”;页,android,xml,http,xml-parsing,Android,Xml,Http,Xml Parsing,我正在尝试获取和RSS提要。但是,HttpEntity返回以下内容: 找不到资源 找不到资源 我使用的地址在我的浏览器中运行良好 MainActivity.java: 。。。 字符串URL=”http://rss.nytimes.com/services/xml/rss/nyt/Africa.xml"; //XML节点密钥 字符串键\u ITEM=“ITEM”//父节点 字符串键\u TITLE=“TITLE”; 字符串键_PUBDATE=“PUBDATE”; String KEY_CRED

我正在尝试获取和RSS提要。但是,HttpEntity返回以下内容:

找不到资源 找不到资源

我使用的地址在我的浏览器中运行良好

MainActivity.java:

。。。
字符串URL=”http://rss.nytimes.com/services/xml/rss/nyt/Africa.xml";
//XML节点密钥
字符串键\u ITEM=“ITEM”//父节点
字符串键\u TITLE=“TITLE”;
字符串键_PUBDATE=“PUBDATE”;
String KEY_CREDIT=“媒体:信用”;
XMLParser=新的XMLParser();
字符串xml=parser.getXmlFromUrl(URL);//获取XML
mOutput+=xml;
Document doc=parser.getdoElement(xml);//获取DOM元素
NodeList nl=doc.getElementsByTagName(键项);
//循环通过所有项目节点
对于(int i=0;ivalue
put(KEY_TITLE,parser.getValue(e,KEY_TITLE));
put(KEY_PUBDATE,parser.getValue(e,KEY_PUBDATE));
put(KEY_CREDIT,parser.getValue(e,KEY_CREDIT));
}
...
XMLParser.java:

公共类XMLParser{
公共字符串getXmlFromUrl(字符串url){
字符串xml=null;
试一试{
//defaultHttpClient
DefaultHttpClient httpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(url);
HttpResponse HttpResponse=httpClient.execute(httpPost);
HttpEntity HttpEntity=httpResponse.getEntity();
xml=EntityUtils.toString(httpEntity);
}捕获(不支持的编码异常e){
e、 printStackTrace();
Log.d(“dsgv”,“无支持的编码异常”);
}捕获(客户端协议例外e){
e、 printStackTrace();
Log.d(“dsgv”、“ClientProtocolException”);
}捕获(IOE异常){
e、 printStackTrace();
Log.d(“dsgv”、“IOException”);
}
//返回XML
返回xml;
}
公共文档getDoElement(字符串xml){
单据单据=空;
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
试一试{
DocumentBuilder db=dbf.newDocumentBuilder();
InputSource is=新的InputSource();
is.setCharacterStream(新的StringReader(xml));
doc=db.parse(is);
}捕获(ParserConfiguration异常e){
Log.e(“错误:,e.getMessage());
返回null;
}捕获(SAXE异常){
Log.e(“错误:,e.getMessage());
返回null;
}捕获(IOE异常){
Log.e(“错误:,e.getMessage());
返回null;
}
//返回DOM
退货单;
}
公共字符串getValue(元素项,字符串str){
NodeList n=item.getElementsByTagName(str);
返回此.getElementValue(n.item(0));
}
公共最终字符串getElementValue(节点元素){
节点子节点;
if(elem!=null){
if(elem.hasChildNodes()){
for(child=elem.getFirstChild();child!=null;child=child.getNextSibling()){
if(child.getNodeType()==Node.TEXT\u节点){
返回child.getNodeValue();
}
}
}
}
返回“”;
} 
}

好的,我找到了答案:

RSS应该使用GET方法获取,而不是POST方法

我换了

HttpPost httpPost = new HttpPost(url);

HttpGet httpGet = new HttpGet(url);