Make sure the connection is always disconnected
This commit is contained in:
parent
ef57893a51
commit
18efaffed4
1 changed files with 14 additions and 10 deletions
|
@ -51,6 +51,7 @@ class Isgd private constructor() {
|
||||||
companion object {
|
companion object {
|
||||||
private fun callApi(url: String): String {
|
private fun callApi(url: String): String {
|
||||||
val connection = URL(url).openConnection() as HttpURLConnection
|
val connection = URL(url).openConnection() as HttpURLConnection
|
||||||
|
try {
|
||||||
connection.setRequestProperty(
|
connection.setRequestProperty(
|
||||||
"User-Agent",
|
"User-Agent",
|
||||||
"Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0"
|
"Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0"
|
||||||
|
@ -62,6 +63,9 @@ class Isgd private constructor() {
|
||||||
connection.responseCode,
|
connection.responseCode,
|
||||||
connection.errorStream.bufferedReader().use { it.readText() })
|
connection.errorStream.bufferedReader().use { it.readText() })
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
connection.disconnect()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getHost(isVgd: Boolean = false): String {
|
private fun getHost(isVgd: Boolean = false): String {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue