I am using the Volley framework in a project where I always need to handle the redirects myself to handle the headers.
How redirects are handled depends right now o
Try on more call with the Location value from the network response headers
Kotlin Implementation
fun fetchRemoteList(
url: String,
context: Context,
callback: OnFetchListCompleted,
firstTry: Boolean = true
) {
val queue = Volley.newRequestQueue(context)
val stringRequest = StringRequest(
Request.Method.GET, url,
Response.Listener { response ->
GlobalScope.launch {
callback.fetchListSucceed()
}
},
Response.ErrorListener { error ->
val locationRedirectUrl: String? = error?.networkResponse?.headers?.get("Location")
if (firstTry && !locationRedirectUrl.isNullOrEmpty()) {
fetchRemoteList(locationRedirectUrl, context, callback, false)
} else {
callback.fetchListFailed(error?.message ?: "")
}
})
queue.add(stringRequest)
}