Play 框架:为什么 cookie 不显示 [英] Play framework: Why the cookie isn't showing

查看:58
本文介绍了Play 框架:为什么 cookie 不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用域设置一个简单的 cookie,但它似乎没有被添加到浏览器的 cookie 存储中.

I'm trying to set a simple cookie with a domain but it seems that it doesn't get added to the browser's cookie store.

这是我添加 cookie 的方法

Here's how I added the cookie

response().setCookie("clientauthtoken", "asdasd", 5000, "/test", "test.com", false, false);

如果我检查 cookie 管理器(Firefox 管理 cookie 的插件),它不会显示我添加的 cookie.

And if I check in the cookie manager (a plugin for Firefox to manage cookies) it doesn't show the cookie I added.

如果我签入会话,是的,它就在那里

If I check in the session, yes it's there

    for (play.mvc.Http.Cookie cockie: response().cookies()) {
        Logger.info(" name " + cockie.name());
        Logger.info(" value " + cockie.value());
        Logger.info(" domain " + cockie.domain());
    }

只有当我添加了域 (test.com) 时才会发生这种情况.如果我将域设置为 null 或空字符串并尝试再次添加 cookie,那么它会同时显示浏览器的 cookie 存储和会话中.那么我在这里缺少什么?或者是不能用域添加cookie.

This happens only if I added the domain (test.com). If I set the domain null or an empty string and try to add the cookie again, then it is showing both the browser's cookie store and in the session. So what I'm missing here? Or is it not possible to add a cookie with a domain.

谢谢.

推荐答案

如果您要添加域的 cookie,则在浏览到 localhost 时无法对其进行测试.为了测试它,您需要做的是编辑操作系统的 hosts 设置(对于 linux 和 OS X,它是 /etc/hosts)并添加:

If you're adding a cookie with a domain, you can't test it when browsing to localhost. What you need to do in order to test it is to edit the hosts settings of your OS (for linux and OS X it's /etc/hosts) and add:

127.0.0.1 test.com

然后你可以通过 http://test.com:9000

这篇关于Play 框架:为什么 cookie 不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆