本文整理汇总了Java中java.net.CookieHandler.get方法的典型用法代码示例。如果您正苦于以下问题:Java CookieHandler.get方法的具体用法?Java CookieHandler.get怎么用?Java CookieHandler.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.CookieHandler
的用法示例。
在下文中一共展示了CookieHandler.get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processCookie
import java.net.CookieHandler; //导入方法依赖的package包/类
void processCookie(String url, Map<String, List<String>> headers) {
if (!isUseCookie()) {
return;
}
try {
CookieHandler cookieManager = getCookieHandler();
Map<String, List<String>> singleMap =
cookieManager.get(URI.create(url), new HashMap<String, List<String>>(0));
List<String> cookies = singleMap.get("Cookie");
if (cookies != null) {
headers.put("Cookie", Collections.singletonList(TextUtils.join(";", cookies)));
}
} catch (Throwable ex) {
LogUtil.e(ex.getMessage(), ex);
}
}
示例2: printCookieInfo
import java.net.CookieHandler; //导入方法依赖的package包/类
static private void printCookieInfo(URI uri) throws IOException {
CookieHandler handler = CookieHandler.getDefault();
Map<String, List<String>> cookieMap = null;
if (handler == null) {
System.out.println("Failing due to lack of CookieHandler class!");
return;
}
System.out.println("Using CookieHandler class: " + handler.getClass().getCanonicalName());
cookieMap = handler.get(uri, new HashMap<String, List<String>>());
for (Map.Entry<String, List<String>> entry : cookieMap.entrySet()) {
System.out.println("Iterating cookiemap with " + entry.getKey() + " => " + entry.getValue());
if (entry.getKey().contains("Cookie")) {
for (String cookie : entry.getValue()) {
System.out.println("Found cookie: " + cookie);
}
}
}
}
示例3: printEnvironment
import java.net.CookieHandler; //导入方法依赖的package包/类
private void printEnvironment() {
Version version = new Version();
addDetailMessage("eID browser applet version: " + version.getVersion());
addDetailMessage("Java version: " + System.getProperty("java.version"));
addDetailMessage("Java vendor: " + System.getProperty("java.vendor"));
addDetailMessage("OS: " + System.getProperty("os.name"));
addDetailMessage("OS version: " + System.getProperty("os.version"));
addDetailMessage("OS arch: " + System.getProperty("os.arch"));
addDetailMessage("Web application URL: " + this.runtime.getDocumentBase());
addDetailMessage("Current time: " + new Date());
/*
* Next we check for the presence of the session cookie.
*/
CookieHandler cookieHandler = CookieHandler.getDefault();
if (null != cookieHandler) {
URL documentBase = this.runtime.getApplet().getDocumentBase();
try {
Map<String, List<String>> headers = cookieHandler.get(documentBase.toURI(),
new HashMap<String, List<String>>());
List<String> cookieHeaderValues = headers.get("Cookie");
if (null == cookieHeaderValues || cookieHeaderValues.isEmpty()) {
addDetailMessage("ERROR: no session cookie detected!");
} else {
/*
* Of course we don't print out the session cookie...
*/
addDetailMessage("session cookie detected");
}
} catch (Exception e) {
addDetailMessage("error getting cookies from default cookie handler");
}
}
}
示例4: addCookie
import java.net.CookieHandler; //导入方法依赖的package包/类
/**
* Conform to the URI of the Cookie is added to the head.
*
* @param uri url.
* @param cookieHandler cookieHandler.
*/
public void addCookie(URI uri, CookieHandler cookieHandler) {
try {
Map<String, List<String>> diskCookies = cookieHandler.get(uri, new HashMap<String, List<String>>());
for (Map.Entry<String, List<String>> entry : diskCookies.entrySet()) {
String key = entry.getKey();
List<String> value = entry.getValue();
if (HEAD_KEY_COOKIE.equalsIgnoreCase(key)) {
add(key, TextUtils.join("; ", value));
}
}
} catch (IOException e) {
Logger.e(e);
}
}