2012-07-07 33 views
0

我使用代码解析来自此链接的RSS IBM - Working with XML on Android ...并且我的URL没有问题。如果我用这个网址:MalformedURLException:未找到协议。 Android上的RSS订阅源

static String feedUrl = "http://clarin.feedsportal.com/c/33088/f/577681/index.rss";

它的工作原理正确的,但如果我用这个网址:

static String feedUrl = "http://www.myworkingdomain.com/api/?m=getFeed&secID=163&lat=0&lng=0&rd=0&d=1";

它给我:

07-07 19:41:30.134: E/AndroidNews(5454): java.lang.RuntimeException: java.net.MalformedURLException: Protocol not found:

我我已经尝试过其他答案的提示...但他们都没有帮助我... 还有其他解决方案吗?

感谢您的帮助!

回答

0

看到你的feedUrl,我假设你想用参数做一个HTTP GET请求。我也遇到了很多麻烦,直到我开始使用StringBuilder和HttpClient。

下面是一些代码,无一例外醒目:

   SAXParserFactory mySAXParserFactory = SAXParserFactory 
        .newInstance(); 
      SAXParser mySAXParser = mySAXParserFactory.newSAXParser(); 
      XMLReader myXMLReader = mySAXParser.getXMLReader(); 
      RSSHandler myRSSHandler = new RSSHandler(); 
      myXMLReader.setContentHandler(myRSSHandler); 

      HttpClient httpClient = new DefaultHttpClient(); 

      StringBuilder uriBuilder = new StringBuilder(
        "http://myworkingdomain.com/api/"); 
      uriBuilder.append("?m=getFeed"); 
      uriBuilder.append("&secID=163"); 

      [...] 

      HttpGet request = new HttpGet(uriBuilder.toString()); 
      HttpResponse response = httpClient.execute(request); 

      int status = response.getStatusLine().getStatusCode(); 

      // we assume that the response body contains the error message 
      if (status != HttpStatus.SC_OK) { 
       ByteArrayOutputStream ostream = new ByteArrayOutputStream(); 
       response.getEntity().writeTo(ostream); 
       Log.e("HTTP CLIENT", ostream.toString()); 
      } 

      InputStream content = response.getEntity().getContent(); 

      // Process feed 

      InputSource myInputSource = new InputSource(content); 
      myInputSource.setEncoding("UTF-8"); 
      myXMLReader.parse(myInputSource); 
      myRssFeed = myRSSHandler.getFeed(); 
      content.close(); 

希望这有助于!

+0

感谢您的回答,我已经实现了您的代码并引发了相同的异常,但现在我明白问题出在解析rss时,而不是解决问题。解析rss“link”标签,使用新的URL(链接),一些链接确实注意到了http://部分。 – 2012-07-08 01:56:25