You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Mathias Cianci <mc...@axecibles.com> on 2004/07/30 09:09:33 UTC

change cookie value

Hello everybody,

Is it possible with httpclient to change the value of a specific 
variable sent in a cookie by a server.

For example, when the server send the cookie var1=5&*var2=7*&var3=4, I 
want to save the cookie var1=5&*var2=174*&var3=4

Thank you for advance,

Mathias
An happy httpclient-user ;-)

Re: change cookie value

Posted by Michael Becke <be...@u.washington.edu>.
Sweet!  Glad you were able to get it working.

Mike

Mathias Cianci wrote:

> Ok!
> 
> It works very fine ;-)
> 
>        Calendar cal = Calendar.getInstance(TimeZone.getDefault());
>        cal.set((Calendar.YEAR),cal.get(Calendar.YEAR)+1);
>        java.util.Date d = cal.getTime();                    HttpClient 
> client = new HttpClient();
>        HttpState hs = client.getState();
>        hs.addCookie(new Cookie("search.msn.fr", "smc_classic", 
> "df=0&af=0&rc=50&nw=0&sc=&rs=1", "/", d, false));
>        hs.addCookie(new Cookie("search.msn.fr", "smc_g", 
> "v=1&pvs=classic&ssp=1&df=1", "/", d, false));
>        client.setState(hs);
>      
> 
> Mathias Cianci a écrit :
> 
>> Thank you Mike.
>>
>> But after a long reflexion, I've found that I've not taken the good 
>> part of the problem.
>>
>> In fact, what I want to do is to send a Cookie in the headers of my 
>> first requested page, no matter the cooklies sets by the server.
>>
>> How to do that ?
>>
>> Mathias
>>
>> PS: my english is not really good, don't hesitate to tell me if I'm 
>> not really comprehensive.
>>
>> Michael Becke a écrit :
>>
>>> Hi Mathias,
>>>
>>> The best way is to just create a new instance of Cookie, copying the 
>>> values you want to keep, and add it to the HttpState.
>>>
>>> Mike
>>>
>>> On Jul 30, 2004, at 3:09 AM, Mathias Cianci wrote:
>>>
>>>> Hello everybody,
>>>>
>>>> Is it possible with httpclient to change the value of a specific 
>>>> variable sent in a cookie by a server.
>>>>
>>>> For example, when the server send the cookie var1=5&*var2=7*&var3=4, 
>>>> I want to save the cookie var1=5&*var2=174*&var3=4
>>>>
>>>> Thank you for advance,
>>>>
>>>> Mathias
>>>> An happy httpclient-user ;-)
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: 
>>> commons-httpclient-dev-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: 
>>> commons-httpclient-dev-help@jakarta.apache.org
>>>
>>>
>>>
>>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Re: change cookie value

Posted by Mathias Cianci <mc...@axecibles.com>.
Ok!

It works very fine ;-)

        Calendar cal = Calendar.getInstance(TimeZone.getDefault());
        cal.set((Calendar.YEAR),cal.get(Calendar.YEAR)+1);
        java.util.Date d = cal.getTime();       
       
        HttpClient client = new HttpClient();
        HttpState hs = client.getState();
        hs.addCookie(new Cookie("search.msn.fr", "smc_classic", 
"df=0&af=0&rc=50&nw=0&sc=&rs=1", "/", d, false));
        hs.addCookie(new Cookie("search.msn.fr", "smc_g", 
"v=1&pvs=classic&ssp=1&df=1", "/", d, false));
        client.setState(hs);
       


Mathias Cianci a écrit :

> Thank you Mike.
>
> But after a long reflexion, I've found that I've not taken the good 
> part of the problem.
>
> In fact, what I want to do is to send a Cookie in the headers of my 
> first requested page, no matter the cooklies sets by the server.
>
> How to do that ?
>
> Mathias
>
> PS: my english is not really good, don't hesitate to tell me if I'm 
> not really comprehensive.
>
> Michael Becke a écrit :
>
>> Hi Mathias,
>>
>> The best way is to just create a new instance of Cookie, copying the 
>> values you want to keep, and add it to the HttpState.
>>
>> Mike
>>
>> On Jul 30, 2004, at 3:09 AM, Mathias Cianci wrote:
>>
>>> Hello everybody,
>>>
>>> Is it possible with httpclient to change the value of a specific 
>>> variable sent in a cookie by a server.
>>>
>>> For example, when the server send the cookie var1=5&*var2=7*&var3=4, 
>>> I want to save the cookie var1=5&*var2=174*&var3=4
>>>
>>> Thank you for advance,
>>>
>>> Mathias
>>> An happy httpclient-user ;-)
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: 
>> commons-httpclient-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: 
>> commons-httpclient-dev-help@jakarta.apache.org
>>
>>
>>
>

Re: change cookie value

Posted by Mathias Cianci <mc...@axecibles.com>.
Thank you Mike.

But after a long reflexion, I've found that I've not taken the good part 
of the problem.

In fact, what I want to do is to send a Cookie in the headers of my 
first requested page, no matter the cooklies sets by the server.

How to do that ?

Mathias

PS: my english is not really good, don't hesitate to tell me if I'm not 
really comprehensive.

Michael Becke a écrit :

> Hi Mathias,
>
> The best way is to just create a new instance of Cookie, copying the 
> values you want to keep, and add it to the HttpState.
>
> Mike
>
> On Jul 30, 2004, at 3:09 AM, Mathias Cianci wrote:
>
>> Hello everybody,
>>
>> Is it possible with httpclient to change the value of a specific 
>> variable sent in a cookie by a server.
>>
>> For example, when the server send the cookie var1=5&*var2=7*&var3=4, 
>> I want to save the cookie var1=5&*var2=174*&var3=4
>>
>> Thank you for advance,
>>
>> Mathias
>> An happy httpclient-user ;-)
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>
>
>

Re: change cookie value

Posted by Michael Becke <be...@u.washington.edu>.
Hi Mathias,

The best way is to just create a new instance of Cookie, copying the 
values you want to keep, and add it to the HttpState.

Mike

On Jul 30, 2004, at 3:09 AM, Mathias Cianci wrote:

> Hello everybody,
>
> Is it possible with httpclient to change the value of a specific 
> variable sent in a cookie by a server.
>
> For example, when the server send the cookie var1=5&*var2=7*&var3=4, I 
> want to save the cookie var1=5&*var2=174*&var3=4
>
> Thank you for advance,
>
> Mathias
> An happy httpclient-user ;-)


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org