Skip to main content

parsing a Stirng URI through proxy - please help

4 replies [Last post]
djmlog103
Offline
Joined: 2008-04-18
Points: 0

hi all,
im doing a search engine program which requires XML parsing. the XML is generated dynamically through yahoo advance search features. my code is this.

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse ("http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=1JKrb.bV34G3LbW.yZdbumTSQpNWQyEyS8.TWhlCZ0wc3OkUJl1SKCsSpDxo&query="+value+"&results="+numberOfResults);

the XML is generated when im using direct internet without any proxies. but when i try this at my university (with proxy), it gives exceptions. i think this is because java.net cant determine the proxy settings. is there a way i can fix this probelm?
please help...
thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
joehw
Offline
Joined: 2004-12-15
Points: 0

Internally, the parser uses URL's openConnection() method to establish a connection. So try set the System properties for your proxy server. For example, to set the HTTP proxy:

System.setProperty("http.proxyHost", "name of your proxy");
System.setProperty("http.proxyPort", "port of you proxy");

Joe

djmlog103
Offline
Joined: 2008-04-18
Points: 0

thanks a lot, it worked.! :D

maneshnambiar
Offline
Joined: 2009-02-05
Points: 0

even i faced the same prob, at my university..............
but in my case the System.setProperty() didnt help, ne suggestion??

joehw
Offline
Joined: 2004-12-15
Points: 0

What's the error message you're getting? Your administrator may be in the best position to provide good information. But if there's authentication requirement, you may set it like this: Authenticator.setDefault( new PasswordAuthentication("myuser","mypassword".toCharArray()));