Solved

Client-side Cookies

Posted on 2001-07-08
10
232 Views
Last Modified: 2006-11-17
I wrote some code that does a form post to a website, which works (I get the html back, and I save it in a file).  Other pages, though, use cookie authentication.  So if I do a form post with my userid and password, I just get the html back that says "turn cookies ON or you can't use these pages".

Question: How do I handle cookies if I'm the client?

Examples?

--Dale--

Additional related question...

How does one monitor the cookie activity of the browser?  Is there some kind of logger out there that shows what's showing up at the browser, and what the browser is sending back?  This would prove very helpful in coding client side cookie handling.

(increased points due to additional work).

--Dale--
0
Comment
Question by:sengsational
  • 6
  • 4
10 Comments
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 6263705
You can using URLConnection, use getHeaderField("set-cookie") to get cookie string FROM a url, or setRequestProperty("cookie", "blah blah") to set the cookie details.

There is also HTTPClient class available which also handles cookies.

Here are some references that may help:
http://www.cookiecentral.com/faq/
http://www.innovation.ch/java/HTTPClient/
http://www.innovation.ch/java/HTTPClient/urlcon_vs_httpclient.html

0
 

Author Comment

by:sengsational
ID: 6282976
Increased points because I'm asking now about how to monitor cookie activity.
0
 
LVL 92

Expert Comment

by:objects
ID: 6282981
That'd be a browser dependant thing, and even if it was available how would you want to monitor it?
An applet only runs while it's page is the one displayed so it not much help.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:sengsational
ID: 6283619
>That'd be a browser dependant thing, and even if it was available how would you want to monitor it?

The idea was to get something that logged cookie activity so that I would understand what information was being sent back and forth.

It could just be dumped to a log with timestamps.

The HTTPClient package, which I have yet to try, but have read about (thanks), says that it handles cookies automatically.  But that would mean I would have to write code to go through several pages with my application (I didn't plan on an applet) in order to establish the right cookie.  If I could monitor or log cookie activity while using a browser, I would be able to have my code send the right cookie, and skip going to various pages in the site.
0
 
LVL 92

Expert Comment

by:objects
ID: 6284362
Cookie information is simply sent in the HTTP headers, so monitoring the interaction is a simple matter of printing the relevant headers.
Have a look at the cookiecentral faq for more info on exactly how cookies work.
0
 

Author Comment

by:sengsational
ID: 6304125
When I said:

> How does one monitor the cookie activity of the browser?  

I meant, is there a tool I can use to monitor activity during a "normal" browser session.  This would let me design the Java application properly.  For instance, if a "user" browser session goes through 5 screens, but the cookies are always the same on screens 1, 2, and 3, those screens could be skipped, as long as I knew what to send with screen 4.

--Dale--
0
 
LVL 92

Expert Comment

by:objects
ID: 6304170
You could find a http sniffer app, that could monitor the http trafic.
0
 
LVL 92

Expert Comment

by:objects
ID: 6304184
0
 

Author Comment

by:sengsational
ID: 6305479
I haven't messed with the sniffer yet, but I sorta cheated by adding that to the question anyway.  The 'answer' was HTTPClient.  I haven't coded anything yet, but from the docs, it looks promising.
0
 
LVL 92

Expert Comment

by:objects
ID: 6305489
Let me know if u have any problems.
Thnaks for the points :)
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question