Retrofit 2 请求的动态 Cookie

发布于 2025-01-10 12:35:56 字数 373 浏览 4 评论 0原文

我已经使用 Retrofit 很长时间了,之前从未遇到过任何严重的可用性问题。所以我的用例非常简单,我必须从我们用来处理一些数据的另一个 API 中获取实体。现在唯一的问题是服务正在使用 Cookies 来接受实体 ID。

因此,这意味着每个请求都需要有与其关联的动态 cookie 集。但目前我在 Retrofit 中看不到任何这样的东西。我可以看到一个旧的 PR,但由于未知原因被拒绝。

Retrofit 团队的任何人都可以在这件事上提供帮助吗?我认为这会很有帮助。如果您需要代码示例,我可以在编辑中提供。

TIA

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

口干舌燥 2025-01-17 12:35:56

实现自定义 CookieJar 并在 OkHttpClient 上设置

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

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

从 jar 中加载 cookie,以发出对 url 的 HTTP 请求。此方法为网络请求返回一个可能为空的 cookie 列表。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文