本文整理汇总了Java中java.net.HttpCookie.getName方法的典型用法代码示例。如果您正苦于以下问题:Java HttpCookie.getName方法的具体用法?Java HttpCookie.getName怎么用?Java HttpCookie.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.HttpCookie
的用法示例。
在下文中一共展示了HttpCookie.getName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: of
import java.net.HttpCookie; //导入方法依赖的package包/类
/**
* Create a new SerializableHttpCookie from a HttpCookie
*
* @param cookie An original cookie
* @return SerializableHttpCookie that have same contents
*/
@NotNull
public static SerializableHttpCookie of(@NotNull HttpCookie cookie) {
SerializableHttpCookie newCookie = new SerializableHttpCookie();
newCookie.name = cookie.getName();
newCookie.value = cookie.getValue();
newCookie.comment = cookie.getComment();
newCookie.commentURL = cookie.getCommentURL();
newCookie.toDiscard = cookie.getDiscard();
newCookie.domain = cookie.getDomain();
newCookie.maxAge = cookie.getMaxAge();
newCookie.path = cookie.getPath();
newCookie.portlist = cookie.getPortlist();
newCookie.secure = cookie.getSecure();
newCookie.version = cookie.getVersion();
// for Android (API level 24)
// https://developer.android.com/reference/java/net/HttpCookie.html#isHttpOnly()
try {
newCookie.httpOnly = cookie.isHttpOnly();
} catch (NoSuchMethodError e) {
newCookie.httpOnly = false;
}
return newCookie;
}
示例2: addHttpCookieFromResponseToHeader
import java.net.HttpCookie; //导入方法依赖的package包/类
public void addHttpCookieFromResponseToHeader(final List<Header> headers, final HttpResponse httpResponse) {
String cookieValue = "";
for (Header header : httpResponse.getHeaders("Set-Cookie")) {
List<HttpCookie> httpCookies = HttpCookie.parse(header.getValue());
for (HttpCookie httpCookie : httpCookies) {
if (!cookieValue.isEmpty()) {
cookieValue += "; ";
}
cookieValue += httpCookie.getName() + "=" + httpCookie.getValue();
}
}
headers.add(new BasicHeader("Cookie", cookieValue));
}
示例3: CookieEntity
import java.net.HttpCookie; //导入方法依赖的package包/类
public CookieEntity(URI uri, HttpCookie cookie) {
this.uri = uri == null ? null : uri.toString();
this.name = cookie.getName();
this.value = cookie.getValue();
this.comment = cookie.getComment();
this.commentURL = cookie.getCommentURL();
this.discard = cookie.getDiscard();
this.domain = cookie.getDomain();
long maxAge = cookie.getMaxAge();
if (maxAge != -1L && maxAge > 0) {
this.expiry = (maxAge * 1000L) + System.currentTimeMillis();
if (this.expiry < 0L) { // 计算溢出?
this.expiry = MAX_EXPIRY;
}
} else {
this.expiry = -1L;
}
this.path = cookie.getPath();
if (!TextUtils.isEmpty(path) && path.length() > 1 && path.endsWith("/")) {
this.path = path.substring(0, path.length() - 1);
}
this.portList = cookie.getPortlist();
this.secure = cookie.getSecure();
this.version = cookie.getVersion();
}
示例4: createCookies
import java.net.HttpCookie; //导入方法依赖的package包/类
private Cookie[] createCookies() {
List<String> strCookies = httpHeaders.get(HttpHeaders.COOKIE);
if (strCookies == null) {
return new Cookie[] {};
}
List<Cookie> result = new ArrayList<>();
for (String strCookie : strCookies) {
List<HttpCookie> httpCookies = HttpCookie.parse(strCookie);
for (HttpCookie httpCookie : httpCookies) {
Cookie cookie = new Cookie(httpCookie.getName(), httpCookie.getValue());
result.add(cookie);
}
}
return result.toArray(new Cookie[result.size()]);
}
示例5: fromString
import java.net.HttpCookie; //导入方法依赖的package包/类
@Override
public NewCookie fromString(final String value) {
if (value == null || value.isEmpty()) {
return null;
}
final List<HttpCookie> httpCookies = HttpCookie.parse(value);
final HttpCookie httpCookie = httpCookies.get(0);
return new NewCookie(
httpCookie.getName(),
httpCookie.getValue(),
httpCookie.getPath(),
httpCookie.getDomain(),
httpCookie.getVersion(),
httpCookie.getComment(),
(int) httpCookie.getMaxAge(),
null,
httpCookie.getSecure(),
httpCookie.isHttpOnly());
}
示例6: copyProxyCookie
import java.net.HttpCookie; //导入方法依赖的package包/类
/**
* Copy cookie from the proxy to the servlet client. Replaces cookie path to local path and renames cookie to avoid
* collisions.
*/
protected void copyProxyCookie(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Header header) {
List<HttpCookie> cookies = HttpCookie.parse(header.getValue());
String path = servletRequest.getContextPath(); // path starts with / or is empty string
path += servletRequest.getServletPath(); // servlet path starts with / or is empty string
for (HttpCookie cookie : cookies) {
// set cookie name prefixed w/ a proxy value so it won't collide w/ other cookies
String proxyCookieName = getCookieNamePrefix() + cookie.getName();
Cookie servletCookie = new Cookie(proxyCookieName, cookie.getValue());
servletCookie.setComment(cookie.getComment());
servletCookie.setMaxAge((int) cookie.getMaxAge());
servletCookie.setPath(path); // set to the path of the proxy servlet
// don't set cookie domain
servletCookie.setSecure(cookie.getSecure());
servletCookie.setVersion(cookie.getVersion());
servletResponse.addCookie(servletCookie);
}
}
示例7: fromString
import java.net.HttpCookie; //导入方法依赖的package包/类
@Override
public Cookie fromString(final String value) {
if (value == null || value.isEmpty()) {
return null;
}
final List<HttpCookie> httpCookies = HttpCookie.parse(value);
final HttpCookie httpCookie = httpCookies.get(0);
return new Cookie(httpCookie.getName(), httpCookie.getValue(), httpCookie.getPath(), httpCookie.getDomain(), httpCookie.getVersion());
}
示例8: handleMessage
import java.net.HttpCookie; //导入方法依赖的package包/类
@Override
public void handleMessage(Message msg) {
PortalFragment fragment = mActivityRef.get();
if (fragment == null) {
return;
}
WebView webview = (WebView) fragmentView
.findViewById(R.id.webview);
switch (msg.what) {
case BaseRunnable.REFRESH:
java.net.CookieStore rawCookieStore = ((java.net.CookieManager)
CookieHandler.getDefault()).getCookieStore();
if (rawCookieStore != null) {
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
try {
URI uri = new URI(PORTAL_URL);
for (HttpCookie cookie : rawCookieStore.get(uri)) {
String cookieString = cookie.getName() + "="
+ cookie.getValue() + "; domain="
+ cookie.getDomain();
cookieManager.setCookie(PORTAL_URL + "myPortal.do",
cookieString);
}
} catch (Exception e) {
e.printStackTrace();
}
}
webview.loadUrl(PORTAL_URL + "aptreeList.do");
break;
case BaseRunnable.ERROR:
webview.loadUrl(PORTAL_URL);
break;
}
fragment.dismissProgressDialog();
Toast.makeText(fragment.getContext(), R.string.web_back_hint, Toast.LENGTH_SHORT)
.show();
}
示例9: handleMessage
import java.net.HttpCookie; //导入方法依赖的package包/类
@Override
public void handleMessage(Message msg) {
PortalActivity activity = mActivityRef.get();
if (activity == null || activity.isFinishing()) {
return;
}
WebView webview = (WebView) activity
.findViewById(R.id.webview);
switch (msg.what) {
case BaseRunnable.REFRESH:
java.net.CookieStore rawCookieStore = ((java.net.CookieManager)
CookieHandler.getDefault()).getCookieStore();
if (rawCookieStore != null) {
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
try {
URI uri = new URI(PORTAL_URL);
for (HttpCookie cookie : rawCookieStore.get(uri)) {
String cookieString = cookie.getName() + "="
+ cookie.getValue() + "; domain="
+ cookie.getDomain();
cookieManager.setCookie(PORTAL_URL + "myPortal.do",
cookieString);
}
} catch (Exception e) {
e.printStackTrace();
}
}
webview.loadUrl(PORTAL_URL + "myPortal.do");
break;
case BaseRunnable.ERROR:
webview.loadUrl(PORTAL_URL);
break;
}
activity.dismissProgressDialog();
Toast.makeText(activity, R.string.web_back_hint, Toast.LENGTH_LONG)
.show();
}
示例10: keyForCookie
import java.net.HttpCookie; //导入方法依赖的package包/类
private String keyForCookie(URI uri, HttpCookie cookie) {
return uri.toString() + COOKIE_KEY_DELIMITER + cookie.getName();
}