Solved

Client-side Cookies

Posted on 2001-07-08
10
250 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

734 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