Subscription support http basic authentication in url.

This commit is contained in:
tiou
2021-08-23 16:49:35 +08:00
parent e9d2ed98af
commit e257c4cb56

View File

@@ -459,10 +459,15 @@ object Utils {
} }
@Throws(IOException::class) @Throws(IOException::class)
fun getUrlContentWithCustomUserAgent(url: String?): String { fun getUrlContentWithCustomUserAgent(urlStr: String?): String {
val conn = URL(url).openConnection() val url = URL(urlStr)
val conn = url.openConnection()
conn.setRequestProperty("Connection", "close") conn.setRequestProperty("Connection", "close")
conn.setRequestProperty("User-agent", "v2rayNG/${BuildConfig.VERSION_NAME}") conn.setRequestProperty("User-agent", "v2rayNG/${BuildConfig.VERSION_NAME}")
url.userInfo?.let {
conn.setRequestProperty("Authorization",
"Basic ${encode(URLDecoder.decode(it,"UTF-8"))}")
}
conn.useCaches = false conn.useCaches = false
return conn.inputStream.use { return conn.inputStream.use {
it.bufferedReader().readText() it.bufferedReader().readText()