I have the following code which is pretty standard for fetching an xml document from the web in Android (from what I understand):
URL rssUrl = new URL("web_1.whatever.com");
SAXParserFactory mySAXParserFactory = SAXParserFactory.newInstance();
SAXParser mySAXParser = mySAXParserFactory.newSAXParser();
XMLReader myXMLReader = mySAXParser.getXMLReader();
RSSHandler myRSSHandler = new RSSHandler();
myXMLReader.setContentHandler(myRSSHandler);
myXMLReader.parse(new InputSource(rssUrl.openStream()));
This works perfectly for most situations. The issue arises when I try to fetch an XML document from a web address that has an underscore, "_", in a subdomain, As in: web_1.whatever.com. openStream() apparently does not work with URLs that have an underscore in them. I for the life of me have not found any documentation on this and would like to find a way around this to make it work for URLs with an underscore. The URL that is entered comes from the user who is hosting the XML file and making them host the XML file on another domain is something I don't want to have to make them do. I have tried everything that I can think of, so any help would be immensely appreciated.
The error I get is below.
03-27 03:44:54.274: WARN/System.err(1051): java.io.IOException: Illegal character in host name at index 0: web_1.whatever.com
03-27 03:44:54.274: WARN/System.err(1051): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:874)
03-27 03:44:54.274: WARN/System.err(1051): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:1152)
03-27 03:44:54.274: WARN/System.err(1051): at java.net.URL.openStream(URL.java:653)
Any ideas? Or is there any place I could get a look at the openStream code?
Thanks.