本文整理汇总了Java中java.net.HttpCookie.getDomain方法的典型用法代码示例。如果您正苦于以下问题:Java HttpCookie.getDomain方法的具体用法?Java HttpCookie.getDomain怎么用?Java HttpCookie.getDomain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.HttpCookie
的用法示例。
在下文中一共展示了HttpCookie.getDomain方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
示例3: 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());
}
示例4: add
import java.net.HttpCookie; //导入方法依赖的package包/类
/**
* Add one cookie into cookie store.
*/
public void add(URI uri, HttpCookie cookie) {
// pre-condition : argument can't be null
if (cookie == null) {
throw new NullPointerException("cookie is null");
}
lock.lock();
try {
// remove the ole cookie if there has had one
cookieJar.remove(cookie);
// add new cookie if it has a non-zero max-age
if (cookie.getMaxAge() != 0) {
cookieJar.add(cookie);
// and add it to domain index
if (cookie.getDomain() != null) {
addIndex(domainIndex, cookie.getDomain(), cookie);
}
if (uri != null) {
// add it to uri index, too
addIndex(uriIndex, getEffectiveURI(uri), cookie);
}
}
} finally {
lock.unlock();
}
}
示例5: 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());
}
示例6: parseCookieMap
import java.net.HttpCookie; //导入方法依赖的package包/类
private static void parseCookieMap(String cookieHeader, HashMap<String,
String> cookieMap) {
List<HttpCookie> cookies = HttpCookie.parse(cookieHeader);
for (HttpCookie cookie : cookies) {
if (AuthenticatedURL.AUTH_COOKIE.equals(cookie.getName())) {
cookieMap.put(cookie.getName(), cookie.getValue());
if (cookie.getPath() != null) {
cookieMap.put("Path", cookie.getPath());
}
if (cookie.getDomain() != null) {
cookieMap.put("Domain", cookie.getDomain());
}
}
}
}
示例7: 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();
}
示例8: 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();
}