javax.ws.rs.core.Cookie vs javax.ws.rs.core.NewCookie,有什么区别? [英] javax.ws.rs.core.Cookie vs javax.ws.rs.core.NewCookie , What is the difference?

查看:366
本文介绍了javax.ws.rs.core.Cookie vs javax.ws.rs.core.NewCookie,有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JAX-RS API中找到两个类 javax.ws.rs.core.Cookie javax.ws.rs.core.NewCookie 。一个比另一个的优点是什么?

I found two classes in JAX-RS API javax.ws.rs.core.Cookie and javax.ws.rs.core.NewCookie. What are the advantages of one over another? I would like to know Which one is recommended to use and when?

提前感谢:)

推荐答案

这不是关于推荐的,它是关于适当。一个用于请求,一个用于响应。您可以看到两个不同的javadoc。

It's not about recommended, it's about appropriate. One is for a request, and one is for a response. You can see the two different javadocs.

Cookie


表示值

Represents the value of a HTTP cookie, transferred in a request.

NewCookie


用于创建在响应中传输的新HTTP Cookie。

Used to create a new HTTP cookie, transferred in a response.


Response 中发送时,$ c $ b

NewCookie 将设置 Set-Cookie 标头与cookie信息, Cookie 将设置 Cookie 请求标题。这是根据HTTP规范。

NewCookie, when sent in the Response, will set a Set-Cookie response header with the cookie information, and Cookie will set the Cookie request header with the cookie information. This is per the HTTP spec.

使用示例:

@GET
public Response get() {
    return Response.ok("blah").cookie(new NewCookie("foo", "bar")).build();
}

[..]

Client client = ClientBuilder.newClient();
Response response = client.target(url).request().cookie(new Cookie("foo", "bar")).get();

这篇关于javax.ws.rs.core.Cookie vs javax.ws.rs.core.NewCookie,有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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