本文整理汇总了Java中com.gargoylesoftware.htmlunit.util.Cookie类的典型用法代码示例。如果您正苦于以下问题:Java Cookie类的具体用法?Java Cookie怎么用?Java Cookie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cookie类属于com.gargoylesoftware.htmlunit.util包,在下文中一共展示了Cookie类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: fillSession
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
/**
* 将登录结果保存到给定会话对象中,并激活给定会话对象。
* @param session 会话对象
* @throws IllegalStateException 登录未成功时抛出
* @throws NetworkException 在发生网络问题时抛出
*/
public void fillSession(Session session) throws BiliLiveException {
try {
if (status != SUCCESS) throw new IllegalStateException("Bad status: " + status);
Set<Cookie> cookies = webClient.getCookieManager().getCookies();
CookieStore store = session.getCookieStore();
store.clear();
for (Cookie cookie : cookies) {
store.addCookie(cookie.toHttpClient()); // HtmlUnit Cookie to HttpClient Cookie
}
if (getStatus() == SUCCESS) session.activate();
} catch (IOException ex) {
throw new NetworkException("IO Exception", ex);
}
}
开发者ID:cqjjjzr,项目名称:BiliLiveLib,代码行数:24,代码来源:SessionLoginHelper.java
示例2: loadCookies
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
private void loadCookies() throws IOException {
CookieManager cm = getWebClient().getCookieManager();
File cookiesFile = Directories.META.getDir("cookies.json");
if (cookiesFile.exists()) {
String content = HTMLUtil.readFile(cookiesFile);
List<BasicClientCookie> list = new Gson().fromJson(content, new TypeToken<List<BasicClientCookie>>() {
}.getType());
for (BasicClientCookie bc : list) {
Cookie c = new Cookie(bc.getDomain(), bc.getName(), bc.getValue());
cm.addCookie(c);
}
}
}
开发者ID:openaudible,项目名称:openaudible,代码行数:18,代码来源:AudibleScraper.java
示例3: saveCookies
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
public void saveCookies() throws IOException {
CookieManager cm = getWebClient().getCookieManager();
ArrayList<BasicClientCookie> list = new ArrayList<>();
for (Cookie c : cm.getCookies()) {
BasicClientCookie bc = new BasicClientCookie(c.getName(), c.getValue());
bc.setDomain(c.getDomain());
bc.setPath(c.getPath());
list.add(bc);
}
File cookiesFile = Directories.META.getDir("cookies.json");
if (cookiesFile.exists()) {
cookiesFile.delete();
}
String o = new Gson().toJson(list);
FileUtils.writeByteArrayToFile(cookiesFile, o.getBytes());
}
开发者ID:openaudible,项目名称:openaudible,代码行数:23,代码来源:AudibleScraper.java
示例4: updateCookies
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
public boolean updateCookies(boolean showBrowser) {
SWTAsync.assertGUI();
if (browser == null || browser.getBrowser().isDisposed()) {
if (showBrowser)
browse("https://www.audible.com");
else
return false;
}
final Collection<Cookie> cookies = browser.getCookies();
if (cookies != null) {
try {
audible.setExternalCookies(cookies);
LOG.info("Set " + cookies.size() + " cookies");
return true;
} catch (Throwable e) {
LOG.info("unable to set cookies: ", e);
}
}
return false;
}
开发者ID:openaudible,项目名称:openaudible,代码行数:27,代码来源:AudibleGUI.java
示例5: completeCloudflareBrowserCheck
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
public static Cookie completeCloudflareBrowserCheck(final String url) {
WebClient completeClient = new WebClient(BrowserVersion.CHROME);
completeClient.getOptions().setCssEnabled(false);
completeClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
final HtmlPage page;
final HtmlElement submitButton;
final HtmlForm challengeForm;
try {
page = completeClient.getPage(url);
completeClient.waitForBackgroundJavaScript(5000);
submitButton = (HtmlElement) page.createElement("button");
submitButton.setAttribute("type", "submit");
challengeForm = (HtmlForm) page.getElementById("challenge-form");
challengeForm.appendChild(submitButton);
submitButton.click();
return completeClient.getCookieManager().getCookie("cf_clearance");
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
开发者ID:Cldfire,项目名称:Forum-Notifier,代码行数:27,代码来源:LoginViewController.java
示例6: Account
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
public Account(Map<String, Object> accountData) {
this.name = new SimpleStringProperty((String) accountData.get("name"));
alertCountProperty = new SimpleStringProperty();
messageCountProperty = new SimpleStringProperty();
postCountProperty = new SimpleStringProperty();
positiveRatingCountProperty = new SimpleStringProperty();
this.accountPic = new SimpleObjectProperty<>(new Image("file:" + accountData.get("picFilePath")));
this.cookies = (Set<Cookie>) accountData.get("cookies");
profileUrl = (String) accountData.get("profileUrl");
picFilePath = (String) accountData.get("picFilePath");
try {
xpathMaps = new AccountXpaths((AccountXpaths) accountData.get("xpathsMap"));
} catch (NullPointerException e) {
xpathMaps = new AccountXpaths(getForum().getType());
}
displayBlock = new AccountDisplayBlock();
}
开发者ID:Cldfire,项目名称:Forum-Notifier,代码行数:21,代码来源:Account.java
示例7: updateResult
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
private void updateResult(TestCase testCase, WebClient webClient,
HtmlPage page) {
if (page != null) {
HtmlHead head = (HtmlHead) page.getElementsByTagName("head").get(0);
HtmlElement base = head.appendChildIfNoneExists("base");
base.setAttribute("href", page.getUrl().toString());
head.removeChild(base);
head.insertBefore(base);
testCase.setResultPageText(page.asText());
testCase.setResultPageHTML(page.asXml());
testCase.setResultURL(page.getUrl());
for (Cookie cookie : webClient.getCookieManager().getCookies()) {
JWebBrowser.setCookie(page.getUrl().toString(), cookie
.toString());
}
}
webClient.closeAllWindows();
webClient.getCookieManager().clearCookies();
webClient.getCache().clear();
}
开发者ID:vetsin,项目名称:SamlSnort,代码行数:23,代码来源:TestRunner.java
示例8: inspectCookies
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
String inspectCookies(Collection<Cookie> col) {
String out = "";
out += "Size:" + col.size();
ArrayList<Cookie> sorted = new ArrayList<>();
sorted.addAll(col);
Collections.sort(sorted, (c1, c2) -> c1.getName().compareTo(c2.getName()));
for (Cookie c : sorted) {
out += c.getName() + "=" + c.getValue() + " [" + c.getDomain() + "]\n";
}
return out;
}
开发者ID:openaudible,项目名称:openaudible,代码行数:16,代码来源:Audible.java
示例9: getCookies
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
public Collection<Cookie> getCookies() {
cookies = null;
SWTAsync.block(new SWTAsync("getCookies") {
@Override
public void task() {
browser.execute("cookieCallback(document.cookie.split( ';' ).map( function( x ) { return x.trim().split( '=' ); } ));");
}
}
);
return cookies;
}
开发者ID:openaudible,项目名称:openaudible,代码行数:14,代码来源:AudibleBrowser.java
示例10: createAccount
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
public static Account createAccount(Set<Cookie> cookies, String name, String profileUrl, String picFilePath, AccountXpaths xpathsMap) {
Map<String, Object> returnAccountData = new HashMap<>();
returnAccountData.put("cookies", cookies);
returnAccountData.put("name", name);
returnAccountData.put("profileUrl", profileUrl);
returnAccountData.put("picFilePath", picFilePath);
returnAccountData.put("xpathsMap", xpathsMap);
return new Account(returnAccountData);
}
开发者ID:Cldfire,项目名称:Forum-Notifier,代码行数:12,代码来源:ForumsStore.java
示例11: updateIdentityUnit
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
private void updateIdentityUnit(String token) {
IdentityUnit unit = new IdentityUnit(this.securityNP.getName(), token);
Set<Cookie> cookies = this.webClient.getCookieManager().getCookies();
if (cookies != null && !cookies.isEmpty()) {
for (Cookie cookie : cookies) {
if (COOKIE_SESSION_ID.equals(cookie.getName())) {
unit.setSessionId(cookie.getValue());
this.securitySID = WebSecuritys.simpleSID(cookie.getValue());
break;
}
}
}
cache.put(IDENTITY_UNIT_KEY, unit);
}
开发者ID:alexmao86,项目名称:weixinmp4j,代码行数:15,代码来源:WeixinmpWebSession.java
示例12: testLogin
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
@Test
public void testLogin() {
weiWS.loginIfNecessary();
URL url = weiWS.getCurrentPage().getUrl();
System.out.println(url.toString());
url = weiWS.getCurrentPage().getBaseURL();
System.out.println(url.toString());
//
Set<Cookie> cookies = weiWS.getInstance().getCookieManager().getCookies();
Assert.assertFalse(cookies.isEmpty());
for (Cookie cookie : cookies) {
System.out.println(cookie.toString());
}
//
HtmlAnchor logout = (HtmlAnchor) weiWS.getCurrentPage().getElementById("logout");
Assert.assertNotNull(logout);
//
IdentityUnit unit = weiWS.lookup(WeixinmpWebSession.IDENTITY_UNIT_KEY);
Assert.assertNotNull(unit);
System.out.println(unit);
Assert.assertEquals(weiWS.getSecurityNP().getName(), unit.getUserName());
Assert.assertNotNull(unit.getAccessToken());
Assert.assertNotNull(unit.getSessionId());
}
开发者ID:alexmao86,项目名称:weixinmp4j,代码行数:28,代码来源:WeixinmpWebSessionTest.java
示例13: testGetToken
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
public void testGetToken() throws FailingHttpStatusCodeException, IOException {
WebClient wc = weiWS.getInstance();
WebRequest wr = new WebRequest(new URL("https://mp.weixin.qq.com/cgi-bin/login"), HttpMethod.POST);
wr.getAdditionalHeaders().put("Accept", "*/*");
wr.getAdditionalHeaders().put("Accept-Encoding", "gzip, deflate, br");
wr.getAdditionalHeaders().put("Accept-Language", "en-US,en;q=0.5");
wr.getAdditionalHeaders().put("Connection", "keep-alive");
// wr.getAdditionalHeaders().put("Content-Length", "86");
wr.getAdditionalHeaders().put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
wr.getAdditionalHeaders().put("Host", "mp.weixin.qq.com");
wr.getAdditionalHeaders().put("Referer", "https://mp.weixin.qq.com/");
wr.getAdditionalHeaders().put("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0");
wr.getAdditionalHeaders().put("X-Requested-With", "XMLHttpRequest");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair("f", "json"));
params.add(new NameValuePair("imgcode", ""));
//3BCEBC34A480F472E27372F9DE2D5592
params.add(new NameValuePair("pwd", "3bcebc34a480f472e27372f9de2d5592"));
params.add(new NameValuePair("username", "[email protected]"));
wr.setRequestParameters(params);
Page page = wc.getPage(wr);
String response = page.getWebResponse().getContentAsString();
System.out.println(response);
Set<Cookie> cookies = weiWS.getInstance().getCookieManager().getCookies();
for (Cookie cookie : cookies) {
System.out.println(cookie.toString());
}
Gson gson = new Gson();
RespWithTokenJSON jsonObj = gson.fromJson(response, RespWithTokenJSON.class);
String homePath = jsonObj.getRedirect_url();
HtmlPage homePage = wc.getPage("https://mp.weixin.qq.com/" + homePath);
HtmlAnchor logout = (HtmlAnchor) homePage.getElementById("logout");
System.out.println(logout);
HtmlPage loginPage = wc.getPage("https://mp.weixin.qq.com");
System.out.println(loginPage.getUrl());
}
开发者ID:alexmao86,项目名称:weixinmp4j,代码行数:40,代码来源:WeixinmpWebSessionTest.java
示例14: printInputs
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
/**
* Prints all the inputs that the fuzzer discovers on the given page and web
* client: - Form input tags (from page) - Cookies (from client) - Url GET
* inputs (from page)
*/
public static void printInputs(WebClient client, HtmlPage page) {
ArrayList<DomElement> inputs = getInputs(page);
System.out.println("--------------------------------------");
System.out.println("Page inputs...");
System.out.println("--------------------------------------");
int n = 0;
for (DomElement input : inputs) {
System.out.print("[Input " + n + "] ");
System.out.print("name: \"" + input.getAttribute("name") + "\"");
System.out.print(" type: \"" + input.getAttribute("type") + "\"");
System.out.println();
n += 1;
}
System.out.println("--------------------------------------");
System.out.println("URL inputs...");
System.out.println("--------------------------------------");
ArrayList<String> urlInputs = getUrlInputs(page.getUrl());
if (urlInputs != null) {
System.out.println(urlInputs);
}
else
{
System.out.println("None found for the URL " + page.getUrl().toString());
}
System.out.println("--------------------------------------");
System.out.println("Cookies...");
System.out.println("--------------------------------------");
Set<Cookie> cookies = client.getCookies(page.getUrl());
n = 0;
for (Cookie cookie : cookies) {
System.out.print("[Cookie " + n + "] ");
System.out.print("name: \"" + cookie.getName() + "\"");
System.out.print(" value: \"" + cookie.getValue() + "\"");
System.out.println();
n += 1;
}
}
开发者ID:gemarcano,项目名称:SWEN-Fuzzer,代码行数:44,代码来源:InputDiscovery.java
示例15: init
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
/**
* <p>Does its best to reset/recreate the WebClient Pool (wcPool) and the link and page consumers.</p>
*/
private void init() {
if (null != wcPool) {
wcPool.close();
}
wcPool = new WebClientPool(threadLimit);
if (disableRedirects) {
wcPool.disableRedirects();
}
if (enabledJavascript) {
wcPool.enableJavaScript();
}
for (Cookie cookie : cookies) {
wcPool.addCookie(cookie);
}
wcPool.setName("Sitecrawler pool");
linkExecutor = Executors.newFixedThreadPool(threadLimit, linkExecutorThreadFactory);
linkService = new ExecutorCompletionService<ProcessPage>(linkExecutor);
int pageExecutorSize = (int) Math.ceil(threadLimit * downloadVsProcessRatio);
pageExecutor = Executors.newFixedThreadPool(pageExecutorSize, pageExecutorThreadFactory);
pageService = new ExecutorCompletionService<Collection<String>>(pageExecutor);
// in bytes
long maxHeap = Runtime.getRuntime().maxMemory();
// to mb
double gbMaxHeap = maxHeap / (1024.0 * 1024.0);
// Final result, rounded
int maxProcessWaiting = (int) (gbMaxHeap * maxProcessWaitingRatio);
setMaxProcessWaiting(maxProcessWaiting);
Object[] args = { wcPool.getName(), threadLimit, threadLimit, pageExecutorSize, maxProcessWaiting };
logger.info("WebClientPool {} created with size {}, linkExecutor with size {}, pageExecutor with size {}, maxProcessWaiting={}", args);
}
开发者ID:forcedotcom,项目名称:SiteCrawler,代码行数:38,代码来源:SiteCrawler.java
示例16: setExternalCookies
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
public void setExternalCookies(Collection<Cookie> cookies) throws Exception {
AudibleScraper s = getScraper(false);
CookieManager cm = s.getWebClient().getCookieManager();
// cm.clearCookies();
try {
// s.setURL("https://www.audible.com/"); // http is fine... better?
s.home();
if (s.checkLoggedIn())
return;
} catch (Throwable th) {
th.printStackTrace();
}
LOG.info("CookieManager: " + inspectCookies(cm.getCookies()));
LOG.info("Browser Cooks: " + inspectCookies(cookies));
int updated = 0;
int found = 0;
for (Cookie c : cookies) {
String name = c.getName();
String value = c.getValue();
Cookie existing = cm.getCookie(name);
if (existing != null) {
found++;
String eval = existing.getValue();
if (eval.equals(value)) {
LOG.info("Same Value as Existing: " + existing + " value=" + value);
} else {
updated++;
LOG.info("Different Value as Existing: " + existing + " value=" + value);
Cookie nc = new Cookie(existing.getDomain(), name, value);
cm.addCookie(nc);
}
} else {
LOG.info("new cookie:" + c);
cm.addCookie(c);
}
}
LOG.info("Found " + found + " cookies. updated:" + updated);
s.home();
}
开发者ID:openaudible,项目名称:openaudible,代码行数:44,代码来源:Audible.java
示例17: getCookies
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
public Set<Cookie> getCookies() {
return cookies;
}
开发者ID:Cldfire,项目名称:Forum-Notifier,代码行数:4,代码来源:Account.java
示例18: setCookies
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
public void setCookies(Set<Cookie> cookies) {
this.cookies = cookies;
}
开发者ID:Cldfire,项目名称:Forum-Notifier,代码行数:4,代码来源:Account.java
示例19: addCookie
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
public void addCookie(Cookie cookie) {
cookies.add(cookie);
}
开发者ID:Cldfire,项目名称:Forum-Notifier,代码行数:4,代码来源:Account.java
示例20: getCookies
import com.gargoylesoftware.htmlunit.util.Cookie; //导入依赖的package包/类
private Set<Cookie> getCookies() {
return webClient.getCookies(baseUrl);
}
开发者ID:AusDTO,项目名称:spring-security-stateless,代码行数:4,代码来源:ApplicationTest.java
注:本文中的com.gargoylesoftware.htmlunit.util.Cookie类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论