0

このコードを使用して、このリンクから RSS を解析していますIBM - Working with XML on Android ...そして、URL にはほとんど問題がありません。この 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 に答える