I am currently reading an XML file from a PHP script (as below) which works fine, however I'd now like to add some form of HTTP timeout to retrieving the XML.
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse("http://www.mywebsite.com/returnsXML");
Can this easily be added given my current approach, or would I need to change the request somehow to support timeouts?
You can open connection manually and set timeout for URLConnection:
URL url = new URL("http://www.mywebsite.com/returnsXML");
URLConnection con = url.openConnection();
con.setConnectTimeout(10000); // 10 seconds
Document doc = docBuilder.parse(con.getInputStream());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With