List of usage examples for org.apache.http.conn.util PublicSuffixMatcherLoader load
public static PublicSuffixMatcher load(final File file) throws IOException
From source file:interoperabilite.webservice.client.ClientCustomPublicSuffixList.java
public final static void main(String[] args) throws Exception { // Use PublicSuffixMatcherLoader to load public suffix list from a file, // resource or from an arbitrary URL PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader .load(new URL("https://publicsuffix.org/list/effective_tld_names.dat")); // Please use the publicsuffix.org URL to download the list no more than once per day !!! // Please consider making a local copy !!! DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher); RFC6265CookieSpecProvider cookieSpecProvider = new RFC6265CookieSpecProvider(publicSuffixMatcher); Lookup<CookieSpecProvider> cookieSpecRegistry = RegistryBuilder.<CookieSpecProvider>create() .register(CookieSpecs.DEFAULT, cookieSpecProvider) .register(CookieSpecs.STANDARD, cookieSpecProvider) .register(CookieSpecs.STANDARD_STRICT, cookieSpecProvider).build(); CloseableHttpClient httpclient = HttpClients.custom().setSSLHostnameVerifier(hostnameVerifier) .setDefaultCookieSpecRegistry(cookieSpecRegistry).build(); try {// ww w. j a v a2 s .c om HttpGet httpget = new HttpGet("https://httpbin.org/"); System.out.println("executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(entity); } finally { response.close(); } } finally { httpclient.close(); } }