Skip to content

Commit

Permalink
HttpHelper#get
Browse files Browse the repository at this point in the history
  • Loading branch information
SaeedDev94 committed Sep 6, 2024
1 parent 404625b commit 3c0a08f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ import io.github.saeeddev94.xray.helper.ProfileTouchHelper
import io.github.saeeddev94.xray.service.TProxyService
import org.json.JSONException
import org.json.JSONObject
import java.net.HttpURLConnection
import java.net.URL

class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {

Expand Down Expand Up @@ -333,7 +331,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
dialog.show()
Thread {
try {
val config = httpGet(link)
val config = HttpHelper().get(link)
runOnUiThread {
dialog.dismiss()
try {
Expand All @@ -352,19 +350,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
}.start()
}

private fun httpGet(link: String): String {
val url = URL(link)
val connection = url.openConnection() as HttpURLConnection
connection.requestMethod = "GET"
connection.connect()
val responseCode = connection.responseCode
return if (responseCode == HttpURLConnection.HTTP_OK) {
connection.inputStream.bufferedReader().use { it.readText() }
} else {
throw Exception("HTTP Error: $responseCode")
}
}

private fun ping() {
if (!vpnService.getIsRunning()) return
binding.pingResult.text = getString(R.string.pingTesting)
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/io/github/saeeddev94/xray/helper/HttpHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ import java.net.URL

class HttpHelper {

fun get(link: String): String {
val url = URL(link)
val connection = url.openConnection() as HttpURLConnection
connection.requestMethod = "GET"
connection.connect()
val responseCode = connection.responseCode
return if (responseCode == HttpURLConnection.HTTP_OK) {
connection.inputStream.bufferedReader().use { it.readText() }
} else {
throw Exception("HTTP Error: $responseCode")
}
}

fun measureDelay(): String {
val start = System.currentTimeMillis()
val connection = getConnection()
Expand Down

0 comments on commit 3c0a08f

Please sign in to comment.