如何使用JAX-RS NewCookie删除服务器上的cookie? [英] How to delete a cookie on server with JAX-RS NewCookie?
本文介绍了如何使用JAX-RS NewCookie删除服务器上的cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要删除服务器上的cookie(通过将 Expires
设置为过去)。我如何这样做与 javax.ws.rs.core.NewCookie
?我尝试这个,但它不工作:
return Response.ok()
.entity hello world!)
.cookie(
new NewCookie(
foo,
,
/,
.com,
1,
no comment,
0,// maxAge
false
)
)
.build );
此代码段生成此HTTP标头:
Set-Cookie:foo =; Version = 1; Comment =no comment; Domain = .example.com; Path = /
/ pre>
此标头不会从服务器中删除Cookie。
解决方案这是它的工作原理(比较脏的方法):
返回Response.ok()
.header(
Set-Cookie,
foo = deleted; Domain = .example.com; Path = /; Expires = Thu,1970年1月1日00:00:01 GMT
);
I want to delete cookie on server (by means of setting Expires
to the past). How can I do this with javax.ws.rs.core.NewCookie
? I'm trying this, but it doesn't work:
return Response.ok()
.entity("hello world!")
.cookie(
new NewCookie(
"foo",
"",
"/",
".example.com",
1,
"no comment",
0, // maxAge
false
)
)
.build();
This snippet produces this HTTP header:
Set-Cookie:foo=;Version=1;Comment="no comment";Domain=.example.com;Path=/
This header doesn't delete the cookie from the server. What is a possible workaround?
解决方案
This is how it works (rather dirty approach):
return Response.ok()
.header(
"Set-Cookie",
"foo=deleted;Domain=.example.com;Path=/;Expires=Thu, 01-Jan-1970 00:00:01 GMT"
);
这篇关于如何使用JAX-RS NewCookie删除服务器上的cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文