JxBrowser之五:清除cache和cookie以及SSL證書處理

一、清除cache和cookiecookie

        //清除cache
 browser.getCacheStorage().clearCache(); browser.getLocalWebStorage().clear(); browser.getSessionWebStorage().clear(); //清除cookie
        CookieStorage cookieStorage = browser.getCookieStorage(); List<Cookie> cookieList = cookieStorage.getAllCookies(); for (Cookie cookie : cookieList) { if (cookie.getDomain().contains("baidu"))//根據需求進行配置
 cookieStorage.delete(cookie); } cookieStorage.save(); //須要保存

 

二、SSL證書處理ide

        BrowserContext browserContext = BrowserContext.defaultContext(); NetworkService networkService = browserContext.getNetworkService(); networkService.setCertificateVerifier(new CertificateVerifier() { @Override public CertificateVerifyResult verify(CertificateVerifyParams params) { // Reject SSL certificate for all "baidu.com" hosts.
                if (params.getHostName().contains("baidu.com")) { //根據需求進行域名修改
                    return CertificateVerifyResult.INVALID; } return CertificateVerifyResult.OK; } });

 

以上。spa

相關文章
相關標籤/搜索