Hele
06/26/2018, 6:52 PMnwh
06/26/2018, 7:05 PM/**
* Dispatches a `GET` request to this URL and returns the resulting body as a string, or `null`
* if no body was returned.
*/
suspend fun URL.text() = suspendCoroutine<String?> {
val call = okHttp.newCall(Request.Builder().url(this@text).get().build())
call.enqueue(object: Callback {
override fun onFailure(call: Call, e: IOException) {
it.resumeWithException(e)
}
override fun onResponse(call: Call, response: Response) {
val body = response.body()!!
it.resume(body.string())
}
})
}
gildor
06/27/2018, 3:21 AMgildor
06/27/2018, 3:21 AMnwh
06/29/2018, 6:49 PMnwh
06/29/2018, 7:12 PMgildor
06/30/2018, 4:05 AMgildor
06/30/2018, 4:09 AM