我看了Google provides 2 different examples of HttpURLConnection usage - Should we call HttpURLConnection's disconnect, or InputStream's close? 我知道在Android上使用close()是正确的。但是,当我关闭与InputStream' clos()的连接时,它需要花费10秒才能完成。我希望在1s完成关闭连接。我该怎么办?
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) {
}
}