Is there a way to get the final URL of a request? I know that I can disable redirections and to this myself, but is there a way to get the current URL I'm loading? Like, if I requested a.com and got redirected to b.com, is there a way to get the name of the url b.com?
Interceptors, according to the documentation, are a powerful mechanism that can monitor, rewrite, and retry the API call. So, when we make an API call, we can either monitor it or perform some tasks.
OkHttp doesn't currently offer asynchronous APIs to receive a response body in parts.
OkHttp is an efficient HTTP & HTTP/2 client for Android and Java applications. It comes with advanced features, such as connection pooling (if HTTP/2 isn't available), transparent GZIP compression, and response caching, to avoid the network completely for repeated requests.
The Chain object in retrofit is an implementation of the Chain of Responsibility design pattern, and each interceptor is a processing object which acquires the result of the previous interceptor through chain.
The response object provides a chain of the requests and responses which were used to obtain it.
To obtain the final URL, call request()
on the Response
for the final Request
which then provides the url()
you desire.
You can follow the entire response chain by calling priorResponse()
and looking at each Response
's associated Request
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With