MalformedURLException:找不到协议。 Android上的RSS源

时间:2012-07-07 23:01:25

标签: android

我正在使用代码来解析来自此链接IBM - Working with XML on Android的RSS ...我对URL的问题没什么问题。如果我使用此网址:

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:

我已经尝试过其他答案的提示......但是没有一个能帮助我... 还有其他解决办法吗?

感谢您的帮助!

1 个答案:

答案 0 :(得分: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();

希望这有帮助!