本文整理汇总了Java中java.net.HttpCookie.setHttpOnly方法的典型用法代码示例。如果您正苦于以下问题:Java HttpCookie.setHttpOnly方法的具体用法?Java HttpCookie.setHttpOnly怎么用?Java HttpCookie.setHttpOnly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.HttpCookie
的用法示例。
在下文中一共展示了HttpCookie.setHttpOnly方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toHttpCookie
import java.net.HttpCookie; //导入方法依赖的package包/类
/**
* Convert to a new HttpCookie
*
* @return HttpCookie that have same contents
* @throws IllegalStateException the name is null
*/
@NotNull
public HttpCookie toHttpCookie() {
if (this.name == null) {
throw new IllegalStateException("Illegal cookie name");
}
HttpCookie cookie = new HttpCookie(this.name, this.value);
cookie.setComment(this.comment);
cookie.setCommentURL(this.commentURL);
cookie.setDiscard(this.toDiscard);
cookie.setDomain(this.domain);
cookie.setMaxAge(this.maxAge);
cookie.setPath(this.path);
cookie.setPortlist(this.portlist);
cookie.setSecure(this.secure);
cookie.setVersion(this.version);
// for Android (API level 24)
// https://developer.android.com/reference/java/net/HttpCookie.html#setHttpOnly(boolean)
try {
cookie.setHttpOnly(this.httpOnly);
} catch (NoSuchMethodError e) {
}
return cookie;
}
示例2: testOf
import java.net.HttpCookie; //导入方法依赖的package包/类
@Test
public void testOf() {
HttpCookie cookie = new HttpCookie("name", "value");
cookie.setComment("comment");
cookie.setCommentURL("commentURL");
cookie.setDiscard(true);
cookie.setDomain("example.com");
cookie.setMaxAge(12345L);
cookie.setPath("/");
cookie.setPortlist("443");
cookie.setSecure(true);
cookie.setHttpOnly(true);
cookie.setVersion(1);
SerializableHttpCookie newCookie = SerializableHttpCookie.of(cookie);
Assert.assertEquals(cookie.getName(), newCookie.getName());
Assert.assertEquals(cookie.getValue(), newCookie.getValue());
Assert.assertEquals(cookie.getComment(), newCookie.getComment());
Assert.assertEquals(cookie.getCommentURL(), newCookie.getCommentURL());
Assert.assertEquals(cookie.getDiscard(), newCookie.getDiscard());
Assert.assertEquals(cookie.getDomain(), newCookie.getDomain());
Assert.assertEquals(cookie.getMaxAge(), newCookie.getMaxAge());
Assert.assertEquals(cookie.getPath(), newCookie.getPath());
Assert.assertEquals(cookie.getPortlist(), newCookie.getPortlist());
Assert.assertEquals(cookie.getSecure(), newCookie.getSecure());
Assert.assertEquals(cookie.isHttpOnly(), newCookie.isHttpOnly());
Assert.assertEquals(cookie.getVersion(), newCookie.getVersion());
}