Skip to content

Instantly share code, notes, and snippets.

@guilhermecarvalhocarneiro
Created October 14, 2019 14:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save guilhermecarvalhocarneiro/12200f1e4a673a318835a5b8a308e9cb to your computer and use it in GitHub Desktop.
val url = "${this.uri}?format=json"
val client = OkHttpClient.Builder()
.readTimeout(Config.readTimeOutAPIDefault, TimeUnit.SECONDS)
.connectTimeout(Config.connectTimeOutAPIDefault, TimeUnit.SECONDS)
.build()
val request = Request.Builder().url(url).build()
client.newCall(request).execute().use { response ->
if (response.isSuccessful){
val responseData = response.body.toString()
try {
val json = JSONObject(responseData)
Log.i("vestter", json.toString())
} catch (e: JSONException) {
e.printStackTrace()
Log.e("vestter", e.toString())
}
Log.i("vestter", responseData)
}else{
Log.e("vestter", response.code.toString())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment