Android SSL下载失败



我试图使用Android下载管理器通过HTTPS下载文件,但似乎总是失败。我已经将问题与这段代码隔离开来。但我看不出这个问题。有什么想法吗?安卓API 29

val uri = URL("https://speed.hetzner.de/100MB.bin")
val conn = uri.openConnection() as HttpsURLConnection
conn.setRequestProperty("Accept-Encoding", "identity")
conn.setRequestProperty("Connection", "close")
val resp = conn.responseCode
val inp = conn.inputStream
val buf = ByteArray(8192)
try {
while (true) {
val len = inp.read(buf)
if (len == -1)
break
}
} catch (e: java.lang.Exception) {
// Log something
// This exception always gets caught ... with some sort of SSL exception.
throw e
}

放入清单文件android:usesCleartextTraffic="真";在"<应用程序";

最新更新