[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Client-side Cookies

Posted on 2001-07-08
10
Medium Priority
?
270 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

868 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