'Dynamic Cookies For Retrofit 2 Requests

I've been using retrofit for quite a long time and haven't faced any serious usability issue before now. So my use case is very simple, I've to fetch an entity from another API that we're using to process a few data. Now the only issue is the service is using Cookies to accept entity id.

So this means that each request needs to have dynamic set of cookie associated with it. But currently I cannot see anything such that in Retrofit. I can see a old PR, but it was rejected for unknown reason.

Can anyone from Retrofit team can help in this matter. I think it will be very helpful. If you need code examples I can provide that in an edit.

TIA



Solution 1:[1]

Implement a custom CookieJar and set on the OkHttpClient

https://square.github.io/okhttp/4.x/okhttp/okhttp3/-cookie-jar/

abstract fun loadForRequest(url: HttpUrl): List<Cookie>

Load cookies from the jar for an HTTP request to url. This method returns a possibly empty list of cookies for the network request.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1