[英]How to list cookies in Play
Using PlayFramework (in Java), I'd like to log the list of all cookies name Play can read. 使用Java中的PlayFramework,我想记录Play可以读取的所有cookie名称的列表。
I tried to call request().cookies()
but it's not a List, it's an object, and there is no List in this object. 我试图调用request().cookies()
但它不是一个List,它是一个对象,并且此对象中没有List。
I can call request().cookie(String name);
我可以调用request().cookie(String name);
but this expect that I know the cookie's name, which I don't. 但这希望我知道Cookie的名称,但我不知道。
How can I do then ? 那我该怎么办?
Here's a solution I just made, I don't know if it's the best, but it works : 这是我刚提出的解决方案,我不知道它是否是最好的,但是它可以工作:
for (String cookieStr : request.headers().get("Cookie")) {
String name = cookieStr.substring(0, cookieStr.indexOf("="));
Logger.info("Name of the cookie : " + name);
Cookie cookie = request.cookie(name); // Get the instance of the cookie !
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.