Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Importing Hotmail Addressbook from Java Client using commons-httpclient APIs

Reply
Thread Tools

Importing Hotmail Addressbook from Java Client using commons-httpclient APIs

 
 
Gamas
Guest
Posts: n/a
 
      02-04-2005
Hi guys,

I am trying to get Hotmail Addressbook Page from my Java App, but
haven't been succesfull.

I am using Jakarta commons-httpclient APIs, JDK1.4.2 to do so. Any help
would be greatly appreciated. Thank you very much.

Below is my code:

public void doImport(String sLogin, String sPassword) throws
Exception {
InputStream result = null;
if(client == null) {
client = new HttpClient();
}

client.getHostConfiguration().setHost("login.passp ort.com",
443, "https");

client.getParams().setCookiePolicy(CookiePolicy.BR OWSER_COMPATIBILITY);
PostMethod authpost = new PostMethod("/ppsecure/post.srf");


NameValuePair action = new NameValuePair("sec", "true");
NameValuePair userid = new NameValuePair("login", sLogin);
NameValuePair password = new NameValuePair("passwd",
sPassword);

//authpost.setRequestBody(new NameValuePair[] {action, userid,
password,ls,id,cbid,da,mspp_shared});
authpost.setRequestBody(new NameValuePair[] {action, userid,
password});
int status = client.executeMethod(authpost);

System.out.println("\nLogin form post: " +
authpost.getStatusLine().toString());

System.out.println("\nbody=\n"+authpost.getRespons eBodyAsString());

CookieSpec cookiespec =
CookiePolicy.getCookieSpec(CookiePolicy.BROWSER_CO MPATIBILITY);
Cookie[] logoncookies = cookiespec.match(
"login.passport.com", 443, "/ppsecure/post.srf", true,
client.getState().getCookies());
System.out.println("Logon cookies:");
if (logoncookies.length == 0) {
vErrorMessages.add("login invalid");
System.out.println("None");
} else {
for (int i = 0; i < logoncookies.length; i++) {
System.out.println("- " + logoncookies[i].toString());

}
}

// release any connection resources used by the method
authpost.releaseConnection();

// Usually a successful form-based login results in a redicrect
to
// another url
statuscode = authpost.getStatusCode();
if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) ||
(statuscode == HttpStatus.SC_MOVED_PERMANENTLY) ||
(statuscode == HttpStatus.SC_SEE_OTHER) ||
(statuscode == HttpStatus.SC_TEMPORARY_REDIRECT)) {
Header header = authpost.getResponseHeader("location");
if (header != null) {
String newuri = header.getValue();
if ((newuri == null) || (newuri.equals(""))) {
newuri = "/";
}
System.out.println("Redirect target: " + newuri);

client.getHostConfiguration().setHost("hotmail.msn .com", 80, "http");
GetMethod redirect = new
GetMethod("/cgi-bin/addresses");

redirect.setFollowRedirects(true);
client.executeMethod(redirect);

System.out.println("Redirect: " +
redirect.getStatusLine().toString());
result = redirect.getResponseBodyAsStream();
BufferedReader reader = new BufferedReader(new
InputStreamReader(result));
StringBuffer sbResult = new StringBuffer();

int r = 0;
while((r = reader.read()) != -1) {
sbResult.append((char)r);
}
reader.close();
addressBook = sbResult.toString();

redirect.releaseConnection();
} else {
vErrorMessages.add("invalid redirect");
System.out.println("Invalid redirect");
}
}
}

This is what I get in my console:
Login form post: HTTP/1.1 200 OK

body=
<HTML><HEAD><meta HTTP-EQUIV="Content-Type" content="text/html;
charset=iso-8859-1"><META HTTP-EQUIV="REFRESH" CONTENT="0;
URL=http://login.passport.net/UICookiesDisabled.srf?rollrs=11"><script>function
OnBack(){}</script></HEAD></HTML>
Logon cookies:
None

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing raw text to unicode format using Standard Java APIs theAndroidGuy Java 6 05-01-2009 08:30 AM
hotmail / aim / yahoo addressbook importer rkmr.em@gmail.com Python 0 03-12-2007 03:30 AM
Importing juno Addressbook into Outlook Express =?Utf-8?B?R2VudGxlIEJlbg==?= Microsoft Certification 0 04-30-2006 03:46 AM
How to translate Japanese String into UTF-32 encoded using Java APIs ? Marat Java 5 11-10-2004 04:34 PM
UML and APIs using Java interfaces Calum MacLean Java 3 07-03-2003 03:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57