I have a Java application that is going out to a login website with the login and password and getting two cookies. Then I try to link to another page within the secure part of that website by sending the cookies. This part is failing -- I get a page telling me that I'm not logged in. I am pretty sure that the second HttpURLConnection is incorrect, but I'm not sure how. Can anyone lead me in the right direction? I'd really appreciate an example that I could look at.

Here is my code:


try {
URL url= new URL("http://sctweb10.sctcorp.com/aweb/comk_procs2.comr_check_client_or_user?cntct_id=myID&cntct_passwd=myPWD");
URLConnection urlConnection = url.openConnection();
int i2 = 0;
for(int i=0;;i++) {
String header=urlConnection.getHeaderField(i);
if(header==null)
break;
if("set-cookie".equalsIgnoreCase (urlConnection.getHeaderFieldKey(i))) {
//For now, I am hardcoding the cookies below, but this is where I got them.
System.out.println(header);
i2++;
}
System.out.println ("i2: " + i2);
}

// **** This is the part that isn't working ****
URL url3 = new URL("http://sctweb11.sctcorp.com/awsearch/sct/sctlogin.asp");
HttpURLConnection lobjConnection = (HttpURLConnection)url3.openConnection();

// I'm using IBM VisualAge, so I am trying both of these:
lobjConnection.setRequestProperty("cookie", "IIDENT=1229;ICNTCT=129"); // for jdk1.3
lobjConnection.setRequestProperty("set-cookie", "IIDENT=1229;ICNTCT=129"); // for jdk1.2

System.out.println("getProperty with set-cookie: " + lobjConnection.getRequestProperty("set-cookie"));
System.out.println("getProperty with cookie: " + lobjConnection.getRequestProperty("cookie"));
lobjConnection.setDoOutput(true);

//Print HTML from resulting webpage.
PrintWriter pw = new PrintWriter(lobjConnection.getOutputStream());
pw.flush();
BufferedReader in3 = new BufferedReader(new InputStreamReader(lobjConnection.getInputStream()));
System.out.println("Received Webpage Content = ");
String inputLine;
while ((inputLine = in3.readLine()) != null) {
System.out.println(inputLine);
}
in3.close();
} catch (Exception e) {
System.out.println("Exception: " + e);
}