【问题标题】:Use cookies in android application在 Android 应用程序中使用 cookie
【发布时间】:2020-01-12 23:21:54
【问题描述】:

我正在尝试在不使用 WebView 的情况下将 cookie 分配给 android 应用程序。 所以我有受授权保护的/login url 和/api/* url。 我想在正确登录后发送 cookie 并使用此 cookie 从/api/* 获取受保护的 url 如何在 Android 应用程序中实现 cookie?

【问题讨论】:

  • How can I implement cookies in android application? 取决于您如何发出网络请求。每种方法都有自己的方式来处理 cookie
  • 我用AndroidNetworking 发出网络请求。但是存在哪些方法?
  • which approaches are exist 可能有 100 个。我不会一一列举,抱歉。您是否尝试过搜索以了解如何在 AndroidNetworking 中使用 cookie?
  • 哈...我正在尝试了解解决方案的方式。但我从你@Vladislav 那里听到的是:'有很多解决方案,......'
  • 请查看 Android 网络文档:amitshekhar.me/Fast-Android-Networking/cookie.html

标签: android cookies


【解决方案1】:

由于您没有使用 WebView 来调用您的 URL,并且 Cookie 通常只是存储小块数据的一种方式,因此我将改用 SharedPreferences。

https://developer.android.com/reference/android/content/SharedPreferences

在这里,您可以存储字符串、整数等密钥对,并可以从应用内的任何位置访问。

或者对于 cookie,您可以使用 OKHttp,就像这个答案建议的那样:How to implement cookie handling on Android using OkHttp?

【讨论】:

    猜你喜欢
    • 2011-09-17
    • 1970-01-01
    • 2013-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 2014-06-21
    • 2014-08-27
    相关资源
    最近更新 更多