如何在Codename One中处理cookie?

时间:2017-03-08 13:00:22

标签: codenameone

在Codename One中处理cookie的最佳方法是什么(并确保它适用于iOS和Android以及未来版本)

我看到ConnectionRequest中有setCookiesEnabled()和setUseNativeCookieStore()方法,人们也说我们应该覆盖cookieReceived(Cookie c)方法。

请指教。谢谢!

1 个答案:

答案 0 :(得分:1)

对于大多数典型的cookie处理,覆盖static void Main(string[] args) { int userSelection; do { userSelection = Menu(); if (userSelection == 2) { loggingOn(); } else if (userSelection == 2) { getMail(); } else if (userSelection == 4) { sendMail(); } } while (userSelection != 4); } public static int Menu() { if (loggedIn()) { Console.WriteLine("__________Menu__________"); Console.WriteLine("1) Close the application"); Console.WriteLine("2) Enter your credentials"); Console.WriteLine("3) Check for messages "); Console.WriteLine("4) Send a message"); Console.WriteLine("________________________"); } else { Console.WriteLine("____________Menu____________"); Console.WriteLine("1) Close the application"); Console.WriteLine("2) Enter your Credentials"); Console.WriteLine("____________________________"); Console.WriteLine("what would like to do?"); } return Convert.ToInt32(Console.ReadLine()); } public static bool loggedIn() { if (gmailAddress == "" || gmailPassword == "") { return false; } else { return true; } } public static void loggingOn() { Console.WriteLine("Enter your gmail address: "); gmailAddress = Console.ReadLine(); Console.WriteLine("Enter your gmail password"); gmailPassword = Console.ReadLine(); } public static void getMail() { string[] messages = Gmail.getMail(gmailAddress, gmailPassword); Console.WriteLine(); Console.WriteLine("_____Messages_____"); for (int i = 0; i < messages.Length; i++) { Console.WriteLine(messages[i]); Console.WriteLine(); } Console.WriteLine("_____________"); } static void sendMail() { Console.WriteLine("To address :"); string toAddress = Console.ReadLine(); Console.WriteLine("Subject :"); string subject = Console.ReadLine(); Console.WriteLine("Message :"); string messageBody = Console.ReadLine(); Gmail.sendMail(gmailAddress, gmailPassword, toAddress, subject, messageBody); Console.WriteLine("message sent"); } 可能是您唯一需要做的事情。您将获得一个解析后的cookieReceived对象,您可以在该方法中使用该对象,并可以实现您的处理逻辑。