Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing cookies back and forth  RSS feed

Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!