I am writing a java client application to login to hotmail. I am using JDK1.2.2 along with JSSE1.0.1. After seting the correct url and collecting the cookie information from "Set-Cookie" header i send the cookie information with userid and password with HttpsURLConnection. When i read the input stream it gives me the login page .... I AM TOTALLY CONFUSED.... I am attaching the code below. ANY HELP WOULD BE GREATLY APPRECIATED.....
import java.io.*;
import java.util.*;
import java.net.*;
import java.text.*;
import java.security.*;
import com.sun.net.ssl.*;
import java.text.SimpleDateFormat;
import java.security.Security.*;
import com.sun.*;
import javax.net.ssl.*;
import javax.security.cert.*;
import javax.net.*;
public class WebPIM
{
public static void main(String[] args)
{
try{
String Location = null;
String Cookie_val ="";
System.out.println("Hi"
;
URL u = new URL("
HttpURLConnection connection = (HttpURLConnection)u.openConnection();
connection.setFollowRedirects(false);
connection.setRequestProperty("Connection","Keep-Alive"
;
connection.setRequestProperty("Cache-Control","cache"
;
connection.setRequestProperty("User-Agent","Mozilla/4.0(compatible;MSIE 4.0;windows 98)"
;
Location = connection.getHeaderField("Location"
;
System.out.println("Location : "+Location);
for(int i=0; i<200;i++)
{
if(connection.getHeaderFieldKey(i)!=null)
{
System.out.println("1st Header: "+connection.getHeaderFieldKey(i));
System.out.print(" "+connection.getHeaderField(i));
if(connection.getHeaderFieldKey(i).equals("Set-Cookie"
)
{
Cookie_val = Cookie_val + connection.getHeaderField(i) + ", ";
}
}
}
System.out.println("Location1 : "+Location);
while(Location!=null)
{
u = new URL(Location);
System.out.println("In Location!=null Location1 : "+Location);
connection = (HttpURLConnection)u.openConnection();
connection.setRequestProperty("Cookie",Cookie_val);
connection.setDoOutput(true);
Location = connection.getHeaderField("Location"
;
if(Location==null)
Location = connection.getHeaderField("Location:"
;
//Find Cookie Value from new Location
for(int i=0; i<200;i++)
{
if(connection.getHeaderFieldKey(i)!=null)
{
System.out.println("2nd Header : "+connection.getHeaderFieldKey(i));
if(connection.getHeaderFieldKey(i).equals("Set-Cookie"
)
{
Cookie_val = Cookie_val + connection.getHeaderField(i) + ", ";
}
else if(connection.getHeaderFieldKey(i).equals("Cache-control"
)
System.out.println("Cahe Control " + connection.getHeaderField(i).equals("Cache-control"
);
}
}
}
System.getProperties().put("java.protocol.handler.pkgs","com.sun.net.ssl.internal. System.out.println("Cookie from previous Request : " +Cookie_val);
// add the default security provider (again, in JSSE1.0.1
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
System.out.println("Before HTTPS : "
;
u = new URL(" com.sun.net.ssl.HttpsURLConnection httpsconnection = (com.sun.net.ssl.HttpsURLConnection) u.openConnection();
System.out.println("After HTTPS : "
;
httpsconnection.setRequestProperty("Cookie",Cookie_val);
httpsconnection.setRequestProperty("Connection","Keep-Alive"
;
httpsconnection.setRequestProperty("User-Agent","Mozilla/4.0(compatible;MSIE 4.0;windows 98)"
;
httpsconnection.setRequestProperty("Cache-Control","cache"
;
httpsconnection.setFollowRedirects(false);
httpsconnection.setRequestMethod("POST"
;
httpsconnection.setDoOutput(true);
PrintWriter out = new PrintWriter(httpsconnection.getOutputStream());
out.print("login" + "=" + URLEncoder.encode("bkhajuri52@hotmail.com"
+ "&"
;
out.print("domain" + "=" + URLEncoder.encode("hotmail.com"
+ "&"
;
out.print("sec" + "=" + URLEncoder.encode(""
+ "&"
;
out.print("passwd" + "=" + URLEncoder.encode("zainab1kha"
);
out.print("logintyped" + "=" + URLEncoder.encode(""
+ "&"
;
out.print("id" + "=" + URLEncoder.encode(""
+ "&"
;
out.print("seclog" + "=" + URLEncoder.encode("0"
+ "&"
;
out.print("ru" + "=" + URLEncoder.encode(""
+ "&"
;
out.print("tw" + "=" + URLEncoder.encode("20"
+ "&"
;
out.print("fs" + "=" + URLEncoder.encode("0"
+ "&"
;
out.print("kv" + "=" + URLEncoder.encode(""
+ "&"
;
out.print("cb" + "=" + URLEncoder.encode(""
+ "&"
;
out.print("cbid" + "=" + URLEncoder.encode(""
+ "&"
;
out.print("ts" + "=" + URLEncoder.encode("0"
+ "&"
;
out.print("da" + "=" + URLEncoder.encode("passport.com"
+ "&"
;
out.print("ns" + "=" + URLEncoder.encode(""
+ "&"
;
out.print("_lang" + "=" + URLEncoder.encode("1033"
);
out.close();
for(int i=0; i<200;i++)
{
if(httpsconnection.getHeaderFieldKey(i)!=null)
{
System.out.println("2nd Header : "+httpsconnection.getHeaderFieldKey(i));
System.out.println(" "+httpsconnection.getHeaderField(i));
if(httpsconnection.getHeaderFieldKey(i).equals("Set-Cookie"
)
{
Cookie_val = Cookie_val + httpsconnection.getHeaderField(i) + ", ";
}
}
}
System.out.println("NEW Cookie Value is : " + Cookie_val);
BufferedReader in = new BufferedReader(new InputStreamReader(httpsconnection.getInputStream()));
String str;
while((str=in.readLine())!=null){
System.out.println(str);
}
}catch(Exception e){
System.out.println(e);
}
}
}
my email address is bkhajuri@yahoo.com [sig][/sig]
import java.io.*;
import java.util.*;
import java.net.*;
import java.text.*;
import java.security.*;
import com.sun.net.ssl.*;
import java.text.SimpleDateFormat;
import java.security.Security.*;
import com.sun.*;
import javax.net.ssl.*;
import javax.security.cert.*;
import javax.net.*;
public class WebPIM
{
public static void main(String[] args)
{
try{
String Location = null;
String Cookie_val ="";
System.out.println("Hi"
URL u = new URL("
HttpURLConnection connection = (HttpURLConnection)u.openConnection();
connection.setFollowRedirects(false);
connection.setRequestProperty("Connection","Keep-Alive"
connection.setRequestProperty("Cache-Control","cache"
connection.setRequestProperty("User-Agent","Mozilla/4.0(compatible;MSIE 4.0;windows 98)"
Location = connection.getHeaderField("Location"
System.out.println("Location : "+Location);
for(int i=0; i<200;i++)
{
if(connection.getHeaderFieldKey(i)!=null)
{
System.out.println("1st Header: "+connection.getHeaderFieldKey(i));
System.out.print(" "+connection.getHeaderField(i));
if(connection.getHeaderFieldKey(i).equals("Set-Cookie"
{
Cookie_val = Cookie_val + connection.getHeaderField(i) + ", ";
}
}
}
System.out.println("Location1 : "+Location);
while(Location!=null)
{
u = new URL(Location);
System.out.println("In Location!=null Location1 : "+Location);
connection = (HttpURLConnection)u.openConnection();
connection.setRequestProperty("Cookie",Cookie_val);
connection.setDoOutput(true);
Location = connection.getHeaderField("Location"
if(Location==null)
Location = connection.getHeaderField("Location:"
//Find Cookie Value from new Location
for(int i=0; i<200;i++)
{
if(connection.getHeaderFieldKey(i)!=null)
{
System.out.println("2nd Header : "+connection.getHeaderFieldKey(i));
if(connection.getHeaderFieldKey(i).equals("Set-Cookie"
{
Cookie_val = Cookie_val + connection.getHeaderField(i) + ", ";
}
else if(connection.getHeaderFieldKey(i).equals("Cache-control"
System.out.println("Cahe Control " + connection.getHeaderField(i).equals("Cache-control"
}
}
}
System.getProperties().put("java.protocol.handler.pkgs","com.sun.net.ssl.internal. System.out.println("Cookie from previous Request : " +Cookie_val);
// add the default security provider (again, in JSSE1.0.1
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
System.out.println("Before HTTPS : "
u = new URL(" com.sun.net.ssl.HttpsURLConnection httpsconnection = (com.sun.net.ssl.HttpsURLConnection) u.openConnection();
System.out.println("After HTTPS : "
httpsconnection.setRequestProperty("Cookie",Cookie_val);
httpsconnection.setRequestProperty("Connection","Keep-Alive"
httpsconnection.setRequestProperty("User-Agent","Mozilla/4.0(compatible;MSIE 4.0;windows 98)"
httpsconnection.setRequestProperty("Cache-Control","cache"
httpsconnection.setFollowRedirects(false);
httpsconnection.setRequestMethod("POST"
httpsconnection.setDoOutput(true);
PrintWriter out = new PrintWriter(httpsconnection.getOutputStream());
out.print("login" + "=" + URLEncoder.encode("bkhajuri52@hotmail.com"
out.print("domain" + "=" + URLEncoder.encode("hotmail.com"
out.print("sec" + "=" + URLEncoder.encode(""
out.print("passwd" + "=" + URLEncoder.encode("zainab1kha"
out.print("logintyped" + "=" + URLEncoder.encode(""
out.print("id" + "=" + URLEncoder.encode(""
out.print("seclog" + "=" + URLEncoder.encode("0"
out.print("ru" + "=" + URLEncoder.encode(""
out.print("tw" + "=" + URLEncoder.encode("20"
out.print("fs" + "=" + URLEncoder.encode("0"
out.print("kv" + "=" + URLEncoder.encode(""
out.print("cb" + "=" + URLEncoder.encode(""
out.print("cbid" + "=" + URLEncoder.encode(""
out.print("ts" + "=" + URLEncoder.encode("0"
out.print("da" + "=" + URLEncoder.encode("passport.com"
out.print("ns" + "=" + URLEncoder.encode(""
out.print("_lang" + "=" + URLEncoder.encode("1033"
out.close();
for(int i=0; i<200;i++)
{
if(httpsconnection.getHeaderFieldKey(i)!=null)
{
System.out.println("2nd Header : "+httpsconnection.getHeaderFieldKey(i));
System.out.println(" "+httpsconnection.getHeaderField(i));
if(httpsconnection.getHeaderFieldKey(i).equals("Set-Cookie"
{
Cookie_val = Cookie_val + httpsconnection.getHeaderField(i) + ", ";
}
}
}
System.out.println("NEW Cookie Value is : " + Cookie_val);
BufferedReader in = new BufferedReader(new InputStreamReader(httpsconnection.getInputStream()));
String str;
while((str=in.readLine())!=null){
System.out.println(str);
}
}catch(Exception e){
System.out.println(e);
}
}
}
my email address is bkhajuri@yahoo.com [sig][/sig]