本文整理匯總了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);
}
}