Until now, I've been using Fuel's async GET http requests and everything works fine.
I now need to send the request in a blocking mode since I need the result before the app continues to run.
Here is a very simple GET http request in blocking mode for testing purposes :
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onStart() {
super.onStart()
val (_, _, result) = "https://httpbin.org/get"
.httpGet()
.responseString()
when (result) {
is Result.Failure -> {
val ex = result.getException()
Log.e("FUEL", ex.toString())
}
is Result.Success -> {
val data = result.get()
tvTest.text = data
}
}
}
}
I always have the error message in LogCat, which means that I always get a Result.Failure
.
Can anyone help on this ?
Thank you very much for your time.
I don't understand it all yet, but I got it working. Here's what I did.
So give this a try :