本文整理汇总了Java中org.apache.http.impl.cookie.RFC6265CookieSpecProvider类的典型用法代码示例。如果您正苦于以下问题:Java RFC6265CookieSpecProvider类的具体用法?Java RFC6265CookieSpecProvider怎么用?Java RFC6265CookieSpecProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RFC6265CookieSpecProvider类属于org.apache.http.impl.cookie包,在下文中一共展示了RFC6265CookieSpecProvider类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDefaultBuilder
import org.apache.http.impl.cookie.RFC6265CookieSpecProvider; //导入依赖的package包/类
/**
* Creates a builder containing the default registry entries, using the provided public suffix matcher.
*/
public static RegistryBuilder<CookieSpecProvider> createDefaultBuilder(final PublicSuffixMatcher publicSuffixMatcher) {
final CookieSpecProvider defaultProvider = new DefaultCookieSpecProvider(publicSuffixMatcher);
final CookieSpecProvider laxStandardProvider = new RFC6265CookieSpecProvider(
RFC6265CookieSpecProvider.CompatibilityLevel.RELAXED, publicSuffixMatcher);
final CookieSpecProvider strictStandardProvider = new RFC6265CookieSpecProvider(
RFC6265CookieSpecProvider.CompatibilityLevel.STRICT, publicSuffixMatcher);
return RegistryBuilder.<CookieSpecProvider>create()
.register(CookieSpecs.DEFAULT, defaultProvider)
.register("best-match", defaultProvider)
.register("compatibility", defaultProvider)
.register(CookieSpecs.STANDARD, laxStandardProvider)
.register(CookieSpecs.STANDARD_STRICT, strictStandardProvider)
.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecProvider())
.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecProvider());
}
示例2: main
import org.apache.http.impl.cookie.RFC6265CookieSpecProvider; //导入依赖的package包/类
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 {
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();
}
}
示例3: main
import org.apache.http.impl.cookie.RFC6265CookieSpecProvider; //导入依赖的package包/类
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 {
HttpGet httpget = new HttpGet("https://remotehost/");
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();
}
}