Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

why new URLConnection in java application can't keep session

Posted on 2003-02-20
8
Medium Priority
?
1,148 Views
Last Modified: 2008-02-01
Hi,
My java-application client work this way:
first request for book list, then request for infomation of a special book by index. By I find the second request can't store the cookie from first session.
Here is my relative code:
URL url = new URL(URLAdresse);
URLConnection urlConnection = url.Connection();
if (!cookie.equals("")){
urlConnection.setRequestProperty("cookie", cookie);
}
urlConnection.connect();

kindly tell me why, thks!

0
Comment
Question by:cyclops-wolf
  • 4
  • 2
7 Comments
 
LVL 2

Expert Comment

by:sfotex
ID: 7997543

urlConnection.setRequestProperty("cookie", cookie);

Should setRequestProperty("cookie" be capitalized? "Cookie"
0
 
LVL 2

Expert Comment

by:sfotex
ID: 7997777

urlConnection.setRequestProperty("cookie", cookie);

Should setRequestProperty("cookie" be capitalized? "Cookie"
0
 

Author Comment

by:cyclops-wolf
ID: 8005371
 I have try "cookie" A"Cookie" and "Cookies", but result is the same.
  It is a demo of strust, download from http://javaboutique.internet.com/tutorials/Swing2/swing2.zip.
  Wellcome to use it and share the pain :)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:cyclops-wolf
ID: 8005379
 I have try "cookie" A"Cookie" and "Cookies", but result is the same.
  It is a demo of strust, download from http://javaboutique.internet.com/tutorials/Swing2/swing2.zip.
  Wellcome to use it and share the pain :)
0
 

Author Comment

by:cyclops-wolf
ID: 8005601
Now I Got it!

To resolve this problem, trim all of the info except "SESSIONID=XXXXXXX". Code should write this way:

URL url = new URL(URLAdresse);
URLConnection urlConnection = url.Connection();
if (!cookie.equals("")){
int pos = cookie.indexOf(';');
String session = cookie.substring(0, pos).trim();
urlConnection.setRequestProperty("cookie",session);
}
urlConnection.connect();

0
 

Accepted Solution

by:
cyclops-wolf earned 0 total points
ID: 8005853

To resolve this problem, trim all of the info except "SESSIONID=XXXXXXX". Code should write this way:

HttpURLConnection huc1 = (HttpURLConnection)conn;
huc1.setRequestMethod("GET");
huc1.setDoOutput(true);
huc1.setDoInput(true);
huc1.setUseCaches(false);
huc1.setDefaultUseCaches(false);
huc1.setFollowRedirects(false);
huc1.setInstanceFollowRedirects(false);
if (!cookie.equals("")){
 int pos = cookie.indexOf(';');
 String session = cookie.substring(0, pos).trim();
 huc1.setRequestProperty("cookie",session);
}
0
 

Expert Comment

by:CleanupPing
ID: 9059181
cyclops-wolf:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

581 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