File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Passing cookies back and forth Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Passing cookies back and forth" Watch "Passing cookies back and forth" New topic

Passing cookies back and forth

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I am trying to access a webpage and retrieve some information, i am required to have a cookie and sign in to retrieve the information. I am able to get the cookie, but I cannot seem to be able to send it back to the webpage. I am doing this as a want to have my application (non-web) be able to retrieve information from the web and return it to the user. Therefore I am trying to simulate a web-browser without actually displaying anything, just parsing out the information that I require.
// section of code that I am using to access web
void BUTgetwebpage_mouseClicked(MouseEvent e) {
try {
// Send data.
String urlstring = "";
String line = "";
urlstring = TFCurl.getText();
URL web = new URL(urlstring);
URLConnection webConnection = web.openConnection();
OutputStreamWriter wr = new OutputStreamWriter
BufferedReader in = new BufferedReader
(new InputStreamReader
// Construct data.
line = "Cookie:" +
line = line + "&" + URLEncoder.encode("User") + "=" +
line = line + "&" + URLEncoder.encode("Password")+ "=" +
line = line + "&" + URLEncoder.encode("LoggonButton") +
"=" + URLEncoder.encode("logon");
String inputLine;
while ((inputLine = in.readLine()) != null)
TACwebpagesource.append(inputLine + '\n');
} catch (MalformedURLException m) { // new URL() failed
TACwebpagesource.append("MalformedURLException" + '\n');
} catch (IOException i) { // openConnection() failed
TACwebpagesource.append("IOException" + '\n');
} catch (Exception u) {
TACwebpagesource.append("Exception" + '\n');
TACwebpagesource.append(u.getMessage()); }

I have access to the servlet as I am testing with our own web page and the servlet requires that it has a cookie passed to it, it is receiving the login information, but the cookie contains the jrun session id and without that I cannot access our site.
Any help or direction to sources of information will be greatly appreciated.
If you require any more information please ask.
Thank You
I agree. Here's the link:
subject: Passing cookies back and forth
It's not a secret anymore!