简体   繁体   English

如何从 Rest Web 服务获取 cookie 值

[英]How to get the cookie value from a Rest Webservice

Which annotation from Jax-RS api was used to retrieve the cookie value? Jax-RS api 中的哪个注释用于检索 cookie 值?

I tried with the below code我尝试使用以下代码

 public String getCookieValue(@Context HttpHeaders headers){
   headers.getCookies()  

 }

above code snippet gives a Map.上面的代码片段给出了一个地图。 how to retrieve a specific cookie value from it..!如何从中检索特定的 cookie 值..!

Thanks谢谢

According to javadoc, headers.getCookies() call retrieves you "a read-only map of cookie name (String) to Cookie".根据 javadoc, headers.getCookies()调用会检索“cookie 名称(字符串)到 Cookie 的只读映射”。

Map<String, Cookie> cookies = hh.getCookies();
Cookie myCookie = cookies.get("your cookie name");

我相信你正在寻找@CookieParam

Since you have mentioned to return String and you are returning a map object, it must not be working.由于您已经提到要返回String并且您正在返回一个map对象,因此它一定无法正常工作。

Try this:尝试这个:

 public String getCookieValue(@Context HttpHeaders headers){
   return headers.getCookies().toString;  
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM