aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Passing cookies back and forth" Watch "Passing cookies back and forth" New topic
Author

Passing cookies back and forth

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
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 = "http://198.53.29.3/servlet/cola.Logon";
String line = "";
urlstring = TFCurl.getText();
URL web = new URL(urlstring);
URLConnection webConnection = web.openConnection();
webConnection.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter
(webConnection.getOutputStream());
BufferedReader in = new BufferedReader
(new InputStreamReader
(webConnection.getInputStream()));
// Construct data.
line = "Cookie:" +
webConnection.getHeaderField("Set-Cookie";
line = line + "&" + URLEncoder.encode("User") + "=" +
URLEncoder.encode("test01");
line = line + "&" + URLEncoder.encode("Password")+ "=" +
URLEncoder.encode("test01");
line = line + "&" + URLEncoder.encode("LoggonButton") +
"=" + URLEncoder.encode("logon");
wr.write(line);
wr.flush();
String inputLine;
while ((inputLine = in.readLine()) != null)
TACwebpagesource.append(inputLine + '\n');
wr.close();
in.close();
} catch (MalformedURLException m) { // new URL() failed
TACwebpagesource.append("MalformedURLException" + '\n');
TACwebpagesource.append(m.getMessage());
} catch (IOException i) { // openConnection() failed
TACwebpagesource.append("IOException" + '\n');
TACwebpagesource.append(i.getMessage());
} 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
Kennedy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing cookies back and forth
 
Similar Threads
How Do I Forward/Redirect Extra Parameters From JSP To ASP via POST?
Converting a python program to Java
Write To A URL and Communicate With The Host Server
Problem in reading Http Response Content
error while submitting an http web request