Solved

Client-side Cookies

Posted on 2001-07-08
10
246 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
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!

 

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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 64
JavaFX TableView not displaying correctly 3 105
JDBC performance 8 29
Java array 21 82
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

749 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