如何在Android应用程序中保存Cookie? [英] how to save cookies in android app?
本文介绍了如何在Android应用程序中保存Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
API创建数据并将其保存在cookie中.它在浏览器上运行良好.但是该Cookie不会保存在android应用中.始终显示空白数组.有人知道吗? Android开发人员是否必须添加任何库来保存Cookie?还是API方面的问题.
API creating and save data in a cookie. It works well on the browser. But that cookie is not saved in the android app. Always show a blank array. Anybody know about this? Do android developer has to add any library to save cookie? or it is API side problem.
推荐答案
您可以尝试一下.
/**
* Checks the response headers for session cookie and saves it if it
* finds it.
*
* @param headers
* Response Headers.
*/
public void checkSessionCookie(Map<String, String> headers)
{
// Config.SET_COOKIE_KEY = "Set-Cookie"
if (headers.containsKey(Config.SET_COOKIE_KEY) && headers.get(Config.SET_COOKIE_KEY).startsWith(Config.SESSION_COOKIE))
{
String cookie = headers.get(Config.SET_COOKIE_KEY);
if (cookie.length() > 0)
{
String[] splitCookie = cookie.split(";");
String[] splitSessionId = splitCookie[0].split("=");
cookie = splitSessionId[1];
// Now here set cookie to your Preference file.
}
}
}
这篇关于如何在Android应用程序中保存Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文