0

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

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

它工作正常,但如果我使用这个 URL:

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:

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

谢谢你的帮助!

4

1 回答 1

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();

希望这可以帮助!

于 2012-07-07T23:07:43.650 回答