• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing cookies back and forth

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic