I am trying to parse an XML file from an HTTP URL. I want to configure a timeout of 15 seconds if the XML fetch takes longer than that, I want to report a timeout. For some reason, the setConnectTimeout and setReadTimeout do not work. Here's the code:
URL url = new URL("http://www.myurl.com/sample.xml");
URLConnection urlConn = url.openConnection();
urlConn.setConnectTimeout(15000);
urlConn.setReadTimeout(15000);
urlConn.setAllowUserInteraction(false);
urlConn.setDoOutput(true);
InputStream inStream = urlConn.getInputStream();
InputSource input = new InputSource(inStream);
And I am catching the SocketTimeoutException.
Thanks
Chris
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…