You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Mike Wertheim <mw...@hyperreal.org> on 2013/11/25 00:41:24 UTC

how to use CookieSpecs

I'm upgrading to from version 4.2.5 of HttpClient to version 4.3.1.

My code has these 2 lines:
final Request request = Request.Get(url);
request.config(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);

Since request.config is now deprecated, what should I replace that second
line with?

I see that version 4.3 provides a new class
called org.apache.http.client.config.CookieSpecs.  The class's javadoc
indicates that this is probably the right class to use, but I don't see any
documentation that describes how to use it or examples that show how to use
it.

Re: how to use CookieSpecs

Posted by Arul Dhesiaseelan <ar...@acm.org>.
You need to use the HttpClient to execute this request. Here is an example:

        RequestConfig config =
RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
        HttpUriRequest request =
RequestBuilder.get().setUri(uri).setConfig(config).build();
        CloseableHttpClient client = HttpClients.createDefault();
        CloseableHttpResponse response = client.execute(request);

I don't believe the Fluent API supports configuring cookies. It has limited
support for configuration unlike the full blown HttpClient native API.


On Sun, Nov 24, 2013 at 7:46 PM, Mike Wertheim <mw...@hyperreal.org> wrote:

> Thanks.
>
> But I'm a bit confused.  My original code created a Request.  The next
> line in my original code is this:
> HttpEntity entity = request.execute().returnResponse().getEntity();
>
> And the subsequent code does some operations on the HttpEntity.
>
> The new code that you provided returns an HttpUriRequest instead of a
> Request.
>
> How do I execute an HttpUriRequest and get the resulting HttpEntitiy?
>
>
>
>
>
> On Sun, Nov 24, 2013 at 6:50 PM, Arul Dhesiaseelan <ar...@acm.org> wrote:
>
>> Hi Mike,
>>
>> This should do the trick.
>>
>>         RequestConfig config =
>> RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
>>         HttpUriRequest request =
>> RequestBuilder.get().setUri(url).setConfig(config).build();
>>
>> - Arul
>>
>>
>> On Sun, Nov 24, 2013 at 1:41 PM, Mike Wertheim <mw...@hyperreal.org> wrote:
>>
>>> I'm upgrading to from version 4.2.5 of HttpClient to version 4.3.1.
>>>
>>> My code has these 2 lines:
>>> final Request request = Request.Get(url);
>>> request.config(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
>>>
>>> Since request.config is now deprecated, what should I replace that second
>>> line with?
>>>
>>> I see that version 4.3 provides a new class
>>> called org.apache.http.client.config.CookieSpecs.  The class's javadoc
>>> indicates that this is probably the right class to use, but I don't see
>>> any
>>> documentation that describes how to use it or examples that show how to
>>> use
>>> it.
>>>
>>
>>
>

Re: how to use CookieSpecs

Posted by Mike Wertheim <mw...@hyperreal.org>.
Thanks.

But I'm a bit confused.  My original code created a Request.  The next line
in my original code is this:
HttpEntity entity = request.execute().returnResponse().getEntity();

And the subsequent code does some operations on the HttpEntity.

The new code that you provided returns an HttpUriRequest instead of a
Request.

How do I execute an HttpUriRequest and get the resulting HttpEntitiy?





On Sun, Nov 24, 2013 at 6:50 PM, Arul Dhesiaseelan <ar...@acm.org> wrote:

> Hi Mike,
>
> This should do the trick.
>
>         RequestConfig config =
> RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
>         HttpUriRequest request =
> RequestBuilder.get().setUri(url).setConfig(config).build();
>
> - Arul
>
>
> On Sun, Nov 24, 2013 at 1:41 PM, Mike Wertheim <mw...@hyperreal.org> wrote:
>
>> I'm upgrading to from version 4.2.5 of HttpClient to version 4.3.1.
>>
>> My code has these 2 lines:
>> final Request request = Request.Get(url);
>> request.config(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
>>
>> Since request.config is now deprecated, what should I replace that second
>> line with?
>>
>> I see that version 4.3 provides a new class
>> called org.apache.http.client.config.CookieSpecs.  The class's javadoc
>> indicates that this is probably the right class to use, but I don't see
>> any
>> documentation that describes how to use it or examples that show how to
>> use
>> it.
>>
>
>

Re: how to use CookieSpecs

Posted by Arul Dhesiaseelan <ar...@acm.org>.
Hi Mike,

This should do the trick.

        RequestConfig config =
RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
        HttpUriRequest request =
RequestBuilder.get().setUri(url).setConfig(config).build();

- Arul


On Sun, Nov 24, 2013 at 1:41 PM, Mike Wertheim <mw...@hyperreal.org> wrote:

> I'm upgrading to from version 4.2.5 of HttpClient to version 4.3.1.
>
> My code has these 2 lines:
> final Request request = Request.Get(url);
> request.config(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
>
> Since request.config is now deprecated, what should I replace that second
> line with?
>
> I see that version 4.3 provides a new class
> called org.apache.http.client.config.CookieSpecs.  The class's javadoc
> indicates that this is probably the right class to use, but I don't see any
> documentation that describes how to use it or examples that show how to use
> it.
>