Return-Path: Delivered-To: apmail-jakarta-httpclient-user-archive@www.apache.org Received: (qmail 56015 invoked from network); 5 Feb 2005 01:30:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 5 Feb 2005 01:30:30 -0000 Received: (qmail 75855 invoked by uid 500); 5 Feb 2005 01:30:30 -0000 Delivered-To: apmail-jakarta-httpclient-user-archive@jakarta.apache.org Received: (qmail 75821 invoked by uid 500); 5 Feb 2005 01:30:29 -0000 Mailing-List: contact httpclient-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: "HttpClient User Discussion" Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-user@jakarta.apache.org Received: (qmail 75805 invoked by uid 99); 5 Feb 2005 01:30:29 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of gamas@evite.com designates 209.104.55.99 as permitted sender) Received: from sun1rly3.tmcs.net (HELO sun1rly3.tmcs.net) (209.104.55.99) by apache.org (qpsmtpd/0.28) with ESMTP; Fri, 04 Feb 2005 17:30:28 -0800 Received: from corpmail.office.tmcs ([172.28.10.16]) by sun1rly3.tmcs.net (8.12.10/8.12.9/200406301403) with ESMTP id j151UQDn006720 for ; Fri, 4 Feb 2005 17:30:26 -0800 Received: from [172.22.40.18] (evt-sun1-18-40-22-172-dhcp [172.22.40.18]) by corpmail.office.tmcs with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2657.72) id DY0Q0HQM; Fri, 4 Feb 2005 17:37:03 -0800 Message-ID: <42042106.1020403@evite.com> Date: Fri, 04 Feb 2005 17:27:34 -0800 From: Gamas Sugiarto User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: httpclient-user@jakarta.apache.org Subject: Importing Hotmail Addressbook from Java Client using commons-httpclient APIs Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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.passport.com", 443, "https"); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); PostMethod authpost = new PostMethod("/ppsecure/post.srf"); NameValuePair action = new NameValuePair("sec", "rem"); NameValuePair userid = new NameValuePair("login", sLogin); NameValuePair password = new NameValuePair("passwd", sPassword); 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.getResponseBodyAsString()); CookieSpec cookiespec = CookiePolicy.getCookieSpec(CookiePolicy.BROWSER_COMPATIBILITY); 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= Logon cookies: None --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: httpclient-user-help@jakarta.apache.org