下面列出了怎么用org.apache.http.impl.cookie.BasicClientCookie2的API类实例代码及写法,或者点击链接到github查看源代码。
private static Cookie rewriteForServer(Cookie cookie, DriverRequest request) {
String name = cookie.getName();
if ("_JSESSIONID".equalsIgnoreCase(name)) {
name = name.substring(1);
}
BasicClientCookie2 httpClientCookie = new BasicClientCookie2(name, cookie.getValue());
httpClientCookie.setSecure(false);
String domain;
if (request.getDriver().getConfiguration().isPreserveHost()) {
domain = UriUtils.extractHostName(request.getOriginalRequest().getRequestLine().getUri());
} else {
domain = request.getBaseUrl().getHost();
}
httpClientCookie.setDomain(domain);
httpClientCookie.setPath("/");
httpClientCookie.setComment(cookie.getComment());
httpClientCookie.setVersion(cookie.getVersion());
return httpClientCookie;
}
/**
* Set the cookie locale to en_US.
*/
private void setCookieLocale(){
cookieStore.addCookie(new BasicClientCookie2("box_locale", "en_US"));
cookieStore.addCookie(new BasicClientCookie2("country", "US"));
cookieStore.addCookie(new BasicClientCookie2("lang", "en-US"));
}