Solved

Client-side Cookies

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

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now