I read Google provides 2 different examples of HttpURLConnection usage - Should we call HttpURLConnection's disconnect, or InputStream's close? and I know use close() on Android is correct. But, when I close connection with InputStream'clos(), it cost 10 second to finish. I want finish to close connection in 1s. How do I do?
private HttpURLConnection getConnection(String uri) throws IOException {
try {
URL url = new URL(ROOT_URL + uri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
DataInputStream dIS = new BufferedInputStream(connection.getInputStream(), 100000);
dIS.close(); //it will finish over 10s
} catch (IOException e) {
}
}