Last active
September 21, 2019 13:49
-
-
Save madnotdead/d9eeb86f1c38696dbb5741f7b32bf451 to your computer and use it in GitHub Desktop.
Networking utility to get data from a URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val SLEEP_TIME = 5000L | |
private val TAG = "CounterAsyncTask" | |
private fun sendGet(urlToCall: String = "https://www.google.com/") { | |
Thread.sleep(SLEEP_TIME) | |
val url = URL(urlToCall) | |
with(url.openConnection() as HttpURLConnection) { | |
requestMethod = "GET" // optional default is GET | |
Log.i(TAG,"\nSent 'GET' request to URL : $url; Response Code : $responseCode") | |
inputStream.bufferedReader().use { | |
it.forEachLine { Log.i(TAG, it) } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment