Ammar Hasan
Ammar Hasan

Reputation: 21

Change DNS of HttpUrlConnection

Using Kotlin, I'm trying to access an URL that is blocked in my country and I need to change the DNS or turn on VPN to make a successful connection.

Is there any way to change the DNS programmatically, or is there any other suitable solution to this problem.

My code:

val url = URL("https://prices2.herokuapp.com/")
val con=url.openConnection() as HttpURLConnection
con.connectTimeout=5000
val inputstream=con.inputStream
val bufferreader=BufferedReader(InputStreamReader(inputstream))
bufferreader.forEachLine {
                    data+=it
                }

Upvotes: 1

Views: 675

Answers (1)

Ken Lee
Ken Lee

Reputation: 51

Use third-party tools (such as dnsjava or MiniDNS) to resolve the IP of your target Hostname. And connect to the target server through the IP directly.

Upvotes: 0

Related Questions