On Fri, 2014-03-21 at 09:13 -0400, Karl Wright wrote:
> Hi Oleg,
>
> I'm looking for equivalents to these 4.2.x code snippets in 4.3.x:
>
> >>>>>>
> params.setParameter(ClientPNames.DEFAULT_HOST,fetchHost);
> HttpClientParams.setCookiePolicy(params,CookiePolicy.BROWSER_COMPATIBILITY);
>
>
> localHttpClient.getCookieSpecs().register(CookiePolicy.BROWSER_COMPATIBILITY,
> new CookieSpecFactory()
> {
>
> public CookieSpec newInstance(HttpParams params)
> {
> return new LaxBrowserCompatSpec();
> }
>
> }
> );
>
> httpClient.getParams().setParameter(ClientPNames.VIRTUAL_HOST,hostHost);
> <<<<<<
>
---
Registry<CookieSpecProvider> cookieSpecRegistry =
RegistryBuilder.<CookieSpecProvider>create()
.register(CookieSpecs.BEST_MATCH, new BestMatchSpecFactory())
.register(CookieSpecs.STANDARD, new RFC2965SpecFactory())
.register(CookieSpecs.BROWSER_COMPATIBILITY, new
LaxBrowserCompatSpec())
.register(CookieSpecs.NETSCAPE, new NetscapeDraftSpecFactory())
.register(CookieSpecs.IGNORE_COOKIES, new IgnoreSpecFactory())
.build();
CloseableHttpClient client = HttpClients.custom()
.setDefaultCookieSpecRegistry(cookieSpecRegistry)
.build();
---
> I did not find any builder methods that knew about virtual hosts or the
> default host; if you have example code that will do the equivalent thing
> based on HttpHost objects I'd love to have it. Also, I create my own
> cookie policy, and then ttell httpclient to use it; it's not clear how you
> are supposed to do this in the new world.
>
> Any advice welcome.
>
The virtual parameter was a mistake. Either use an explicit target host
(see below) or use a custom route planner
---
CloseableHttpClient client = HttpClients.createDefault();
HttpHost target = new HttpHost("www.google.com");
HttpGet get = new HttpGet("http://www.google.ru/");
CloseableHttpResponse response = client.execute(target, get);
---
Hope this helps
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]