Added attempt to update subscription via proxy
https://github.com/2dust/v2rayNG/issues/2760
This commit is contained in:
@@ -540,10 +540,22 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
|
||||
}
|
||||
Log.d(ANG_PACKAGE, url)
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val configText = try {
|
||||
var configText = try {
|
||||
Utils.getUrlContentWithCustomUserAgent(url)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
""
|
||||
}
|
||||
if(configText.isEmpty()) {
|
||||
configText = try {
|
||||
val httpPort = Utils.parseInt(settingsStorage?.decodeString(AppConfig.PREF_HTTP_PORT), AppConfig.PORT_HTTP.toInt())
|
||||
Utils.getUrlContentWithCustomUserAgent(url, httpPort)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
""
|
||||
}
|
||||
}
|
||||
if(configText.isEmpty()) {
|
||||
launch(Dispatchers.Main) {
|
||||
toast("\"" + it.second.remarks + "\" " + getString(R.string.toast_failure))
|
||||
}
|
||||
|
||||
@@ -352,9 +352,18 @@ object Utils {
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun getUrlContentWithCustomUserAgent(urlStr: String?): String {
|
||||
fun getUrlContentWithCustomUserAgent(urlStr: String?, httpPort: Int = 0): String {
|
||||
val url = URL(urlStr)
|
||||
val conn = url.openConnection()
|
||||
val conn = if (httpPort == 0) {
|
||||
url.openConnection()
|
||||
} else {
|
||||
url.openConnection(
|
||||
Proxy(
|
||||
Proxy.Type.HTTP,
|
||||
InetSocketAddress("127.0.0.1", httpPort)
|
||||
)
|
||||
)
|
||||
}
|
||||
conn.setRequestProperty("Connection", "close")
|
||||
conn.setRequestProperty("User-agent", "v2rayNG/${BuildConfig.VERSION_NAME}")
|
||||
url.userInfo?.let {
|
||||
|
||||
Reference in New Issue
Block a user