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 tommmmmm <to...@gmail.com> on 2012/04/17 11:28:19 UTC

How to get cookies that are about to be sent?

How to get cookies that are about to be sent?

I read
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html
Nothing there. Only how to get cookies from the execution. And I am not
interested in that. I want to get cookies before execution.

I found some topics on stack overflow but getCookieStore
 method simply doesn't exist.

Any ideas?

-- 
Tomasz P.

Re: How to get cookies that are about to be sent?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, Apr 17, 2012 at 11:35:21AM +0200, tommmmmm wrote:
> One more thing,
> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/index.html
> says and I quote: 4.1.3
> 
> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html#d5e816
> says
> and I quote:
> 
> 
> httpclient.setCookieStore(cookieStore);
> 
> And that method doesn't exit in HttpClient at all. So the official tutorial
> itself is wrong. And yes I triple checked it I am using 4.1.3 not 4.1.2 or
> anything like that.
> 
> 


Ahhh. Not again.

http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/AbstractHttpClient.html#setCookieStore%28org.apache.http.client.CookieStore%29

Oleg


> On 17 April 2012 11:30, tommmmmm <to...@gmail.com> wrote:
> 
> >
> >
> > On 17 April 2012 11:28, tommmmmm <to...@gmail.com> wrote:
> >
> >> How to get cookies that are about to be sent?
> >>
> >> I read
> >> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html
> >> Nothing there. Only how to get cookies from the execution. And I am not
> >> interested in that. I want to get cookies before execution.
> >>
> >> I found some topics on stack overflow but getCookieStore
> >>  method simply doesn't exist.
> >>
> >> Any ideas?
> >>
> >> --
> >> Tomasz P.
> >>
> >>
> > I also found a solution with client.getState().getCookies();
> >
> > http://www.java2s.com/Code/Java/Apache-Common/GetCookievalueandsetcookievalue.htm
> >
> > However the method getState doesn't exist at all....
> >
> > All the good methods are gone in 4.x ?
> >
> 
> 
> 
> -- 
> Tomasz P.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: How to get cookies that are about to be sent?

Posted by tommmmmm <to...@gmail.com>.
One more thing,
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/index.html
says and I quote: 4.1.3

http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html#d5e816
says
and I quote:


httpclient.setCookieStore(cookieStore);

And that method doesn't exit in HttpClient at all. So the official tutorial
itself is wrong. And yes I triple checked it I am using 4.1.3 not 4.1.2 or
anything like that.


On 17 April 2012 11:30, tommmmmm <to...@gmail.com> wrote:

>
>
> On 17 April 2012 11:28, tommmmmm <to...@gmail.com> wrote:
>
>> How to get cookies that are about to be sent?
>>
>> I read
>> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html
>> Nothing there. Only how to get cookies from the execution. And I am not
>> interested in that. I want to get cookies before execution.
>>
>> I found some topics on stack overflow but getCookieStore
>>  method simply doesn't exist.
>>
>> Any ideas?
>>
>> --
>> Tomasz P.
>>
>>
> I also found a solution with client.getState().getCookies();
>
> http://www.java2s.com/Code/Java/Apache-Common/GetCookievalueandsetcookievalue.htm
>
> However the method getState doesn't exist at all....
>
> All the good methods are gone in 4.x ?
>



-- 
Tomasz P.

Re: How to get cookies that are about to be sent?

Posted by tommmmmm <to...@gmail.com>.
Thank you for help :)

Works flawlessly !

Re: How to get cookies that are about to be sent?

Posted by kim young ill <kh...@googlemail.com>.
On Tue, Apr 17, 2012 at 12:01 PM, tommmmmm <to...@gmail.com> wrote:

> On 17 April 2012 11:56, Sam Crawford <sa...@gmail.com> wrote:
>
> > It is there... I suspect you may not be using the DefaultHttpClient
> > class. This has methods for both setCookieStore and getCookieStore.
> > I've just checked the source for 4.1.3, it's certainly there.
> >
> >
>  HttpClient httpClient = new DefaultHttpClient();
>


try

DefaultHttpClient httpClient = new DefaultHttpClient();


i think AbstractHttpClient will work too.


> and I've printed my classpath just to be 100% sure - there is this line:
>
>   -
>
> jar:file:/home/min/ucng/javaLibs/httpcomponents-client-4.1.3/lib/httpclient-4.1.3.jar
>
>
> I also tried typing the method manually in case Netbeans just doesn't see
> it. Got compilation error symbol not found, so getCookieStore really isn't
> there.
>
> I also tried calling getCookieStore as a static method
> HttpClient.getCookieStore(). Also didn't work.
>

Re: How to get cookies that are about to be sent?

Posted by Sam Crawford <sa...@gmail.com>.
Look at the examples again. Specifically example 3.7, where
setCookieStore is used. You'll note that the httpClient variable is
declared with the type DefaultHttpClient (on the left hand side). Your
code below is not doing this (you're assigning to a variable of type
HttpClient, which is an interface that doesn't have the setCookieStore
method).

So you should change your code to use:

DefaultHttpClient httpClient = new DefaultHttpClient();

Thanks,

Sam



On 17 April 2012 11:01, tommmmmm <to...@gmail.com> wrote:
> On 17 April 2012 11:56, Sam Crawford <sa...@gmail.com> wrote:
>
>> It is there... I suspect you may not be using the DefaultHttpClient
>> class. This has methods for both setCookieStore and getCookieStore.
>> I've just checked the source for 4.1.3, it's certainly there.
>>
>>
>  HttpClient httpClient = new DefaultHttpClient();
>
> and I've printed my classpath just to be 100% sure - there is this line:
>
>   -
>   jar:file:/home/min/ucng/javaLibs/httpcomponents-client-4.1.3/lib/httpclient-4.1.3.jar
>
>
> I also tried typing the method manually in case Netbeans just doesn't see
> it. Got compilation error symbol not found, so getCookieStore really isn't
> there.
>
> I also tried calling getCookieStore as a static method
> HttpClient.getCookieStore(). Also didn't work.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: How to get cookies that are about to be sent?

Posted by tommmmmm <to...@gmail.com>.
On 17 April 2012 11:56, Sam Crawford <sa...@gmail.com> wrote:

> It is there... I suspect you may not be using the DefaultHttpClient
> class. This has methods for both setCookieStore and getCookieStore.
> I've just checked the source for 4.1.3, it's certainly there.
>
>
 HttpClient httpClient = new DefaultHttpClient();

and I've printed my classpath just to be 100% sure - there is this line:

   -
   jar:file:/home/min/ucng/javaLibs/httpcomponents-client-4.1.3/lib/httpclient-4.1.3.jar


I also tried typing the method manually in case Netbeans just doesn't see
it. Got compilation error symbol not found, so getCookieStore really isn't
there.

I also tried calling getCookieStore as a static method
HttpClient.getCookieStore(). Also didn't work.

Re: How to get cookies that are about to be sent?

Posted by Sam Crawford <sa...@gmail.com>.
It is there... I suspect you may not be using the DefaultHttpClient
class. This has methods for both setCookieStore and getCookieStore.
I've just checked the source for 4.1.3, it's certainly there.

Sam


On 17 April 2012 10:47, tommmmmm <to...@gmail.com> wrote:
> On 17 April 2012 11:38, Sam Crawford <sa...@gmail.com> wrote:
>
>> Look at the last example (section 3.9) on the page you referenced
>> (
>> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html
>> )
>>
>> You can retrieve the CookieStore later using:
>>
>> CookieStore store = localContext.getAttribute(ClientContext.COOKIE_STORE);
>>
>>
>>
> But it requires me to add localContext to EACH http.execute method.
> And I won't search for 20+ executions scattered in 3 files.
>
> You solution is exactly what I don't want to do.
> Even without saving the cookies to some separate place HttpClient knows
> what to send, so it must be storing the cookies somewhere. The question is
> where....

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: How to get cookies that are about to be sent?

Posted by tommmmmm <to...@gmail.com>.
On 17 April 2012 11:38, Sam Crawford <sa...@gmail.com> wrote:

> Look at the last example (section 3.9) on the page you referenced
> (
> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html
> )
>
> You can retrieve the CookieStore later using:
>
> CookieStore store = localContext.getAttribute(ClientContext.COOKIE_STORE);
>
>
>
But it requires me to add localContext to EACH http.execute method.
And I won't search for 20+ executions scattered in 3 files.

You solution is exactly what I don't want to do.
Even without saving the cookies to some separate place HttpClient knows
what to send, so it must be storing the cookies somewhere. The question is
where....

Re: How to get cookies that are about to be sent?

Posted by Sam Crawford <sa...@gmail.com>.
Look at the last example (section 3.9) on the page you referenced
(http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html)

You can retrieve the CookieStore later using:

CookieStore store = localContext.getAttribute(ClientContext.COOKIE_STORE);



On 17 April 2012 10:30, tommmmmm <to...@gmail.com> wrote:
> On 17 April 2012 11:28, tommmmmm <to...@gmail.com> wrote:
>
>> How to get cookies that are about to be sent?
>>
>> I read
>> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html
>> Nothing there. Only how to get cookies from the execution. And I am not
>> interested in that. I want to get cookies before execution.
>>
>> I found some topics on stack overflow but getCookieStore
>>  method simply doesn't exist.
>>
>> Any ideas?
>>
>> --
>> Tomasz P.
>>
>>
> I also found a solution with client.getState().getCookies();
> http://www.java2s.com/Code/Java/Apache-Common/GetCookievalueandsetcookievalue.htm
>
> However the method getState doesn't exist at all....
>
> All the good methods are gone in 4.x ?

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: How to get cookies that are about to be sent?

Posted by tommmmmm <to...@gmail.com>.
On 17 April 2012 11:28, tommmmmm <to...@gmail.com> wrote:

> How to get cookies that are about to be sent?
>
> I read
> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html
> Nothing there. Only how to get cookies from the execution. And I am not
> interested in that. I want to get cookies before execution.
>
> I found some topics on stack overflow but getCookieStore
>  method simply doesn't exist.
>
> Any ideas?
>
> --
> Tomasz P.
>
>
I also found a solution with client.getState().getCookies();
http://www.java2s.com/Code/Java/Apache-Common/GetCookievalueandsetcookievalue.htm

However the method getState doesn't exist at all....

All the good methods are gone in 4.x ?

Re: Question about spaces in cookie values

Posted by ll...@oreillyauto.com.
Oleg Kalnichevski <ol...@apache.org> wrote on 04/17/2012 05:09:11 PM:

> On Tue, 2012-04-17 at 08:52 -0500, llowder@oreillyauto.com wrote:
> > Does HTTPClient4 have any known issues with having spaces in cookies?
> >
>
> White spaces in cookie values are legal for legacy (Netscape style)
> cookies and for standard HTTP cookies as long as they are enclosed with
> quotation marks. Cookie values with white spaces not enclosed with
> quotation marks may be treated as ambiguous by the strict (standard
> compliant) cookie policies.

My understanding of both specifications is that Netscape disallowed
whitespace unless you used URL Encoding or a similar encoding, though it
did not specify one in particular, and that in RFC 2109 (and the newer one
too) the value was defined as a being either a token (no white space or
special characters) or a quoted string.

>
> > I have a webapp I am working with, and some of the cookies have spaces
in
> > the value. This does not present a problem in my browser, but it does
in
> > the app i am using (specifically, jmeter 2.6). I do have it set to use
> > "compatibility" mode.
> >
> > The odd thing is, when I look in jmeter logs & results, in fiddler and
even
> > in the Apache logs, I see the full cookie value, even the space and
text
> > after it.  However, my tomcat logs show the cookie value being
truncated at
> > the space.
> >
> > As a separate test, I did create a java project of my own that does the
> > same set of requests I am using in jmeter - and I got the same results
> > where I am unable to login successfully, and again due to that space -
even
> > though the line that prints the cookies shows the full cookies.
> >
> > Any ideas or suggestions?
> >
>
> If you post the exact cookie header your application is having the
> problem with I should be able to tell how different cookie policies
> would end up handling it.


I was going through stuff again to find the headers, and find them exact as
I could, and then suddenly I noticed something I had missed before.

What is causing this problem is a bug that was "resolved" as "won't fix"


Httpclient is stripping the quotes from the value section of the cookie.

See: https://issues.apache.org/jira/browse/HTTPCLIENT-1006

I would have to agree with Marc that this is wrong behavior, especially for
a "browser compatibility" mode, though even under the various RFCs this is
wrong as they explicitly state that a quoted string is valid and legal for
value, and you can't have a quoted string without quotes.

I am using httpclient 4.1.3 in my direct tests and whatever version of
httpclient is used with Jmeter 2.6 R1237317

>From reading that one bug report, it looks like I will have to make some
changes to the cookie policy specification, though I am unsure how to do
that. I did a little looking yesterday and wasn't really able to find much
on how to actually do that, so if I could be pointed in the direction of
how to do that, I would appreciate it (I can program, but I am an admin not
a programmer).


Lee Lowder

This communication and any attachments are confidential, protected by Communications Privacy Act 18 USCS � 2510, solely for the use of the intended recipient, and may contain legally privileged material. If you are not the intended recipient, please return or destroy it immediately. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Question about spaces in cookie values

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Tue, 2012-04-17 at 08:52 -0500, llowder@oreillyauto.com wrote:
> Does HTTPClient4 have any known issues with having spaces in cookies?
> 

White spaces in cookie values are legal for legacy (Netscape style)
cookies and for standard HTTP cookies as long as they are enclosed with
quotation marks. Cookie values with white spaces not enclosed with
quotation marks may be treated as ambiguous by the strict (standard
compliant) cookie policies. 

> I have a webapp I am working with, and some of the cookies have spaces in
> the value. This does not present a problem in my browser, but it does in
> the app i am using (specifically, jmeter 2.6). I do have it set to use
> "compatibility" mode.
> 
> The odd thing is, when I look in jmeter logs & results, in fiddler and even
> in the Apache logs, I see the full cookie value, even the space and text
> after it.  However, my tomcat logs show the cookie value being truncated at
> the space.
> 
> As a separate test, I did create a java project of my own that does the
> same set of requests I am using in jmeter - and I got the same results
> where I am unable to login successfully, and again due to that space - even
> though the line that prints the cookies shows the full cookies.
> 
> Any ideas or suggestions?
> 

If you post the exact cookie header your application is having the
problem with I should be able to tell how different cookie policies
would end up handling it.

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Question about spaces in cookie values

Posted by ll...@oreillyauto.com.
Does HTTPClient4 have any known issues with having spaces in cookies?

I have a webapp I am working with, and some of the cookies have spaces in
the value. This does not present a problem in my browser, but it does in
the app i am using (specifically, jmeter 2.6). I do have it set to use
"compatibility" mode.

The odd thing is, when I look in jmeter logs & results, in fiddler and even
in the Apache logs, I see the full cookie value, even the space and text
after it.  However, my tomcat logs show the cookie value being truncated at
the space.

As a separate test, I did create a java project of my own that does the
same set of requests I am using in jmeter - and I got the same results
where I am unable to login successfully, and again due to that space - even
though the line that prints the cookies shows the full cookies.

Any ideas or suggestions?

Thank you.


Lee Lowder

This communication and any attachments are confidential, protected by Communications Privacy Act 18 USCS � 2510, solely for the use of the intended recipient, and may contain legally privileged material. If you are not the intended recipient, please return or destroy it immediately. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org