hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Prasad Sethumadhavan" <PSethumadha...@sandcherry.com>
Subject RE: Importing Hotmail Addressbook from Java Client using commons-httpclient APIs
Date Sat, 05 Feb 2005 02:15:49 GMT
Hi Gamas,
It looks like hotmail.com thinks that cookies are disabled as it is
redirecting you to a cookies disabled URL.
There is a example that is meant for form based authentication...

http://svn.apache.org/viewcvs.cgi/jakarta/commons/proper/httpclient/trun
k/src/examples/FormLoginDemo.java?view=markup

Hope this helps

Thanks
Prasad

-----Original Message-----
From: Gamas Sugiarto [mailto:gamas@evite.com] 
Sent: Friday, February 04, 2005 7:02 PM
To: Julius Davies
Cc: HttpClient User Discussion
Subject: Re: Importing Hotmail Addressbook from Java Client using
commons-httpclient APIs

Hi Julius,

Thank you very much for your suggestion. I tried "User-Agent" header
just you suggested, but still get the same response.

This is the new code that I did. Any other suggestion :

InputStream result = null;
        if(client == null) {
            client = new HttpClient();
        }
        
        client.getHostConfiguration().setHost("login.passport.com", 443,
"https");
        client.getParams().setCookiePolicy(CookiePolicy.DEFAULT);
        client.getState().setCredentials(null, "passport.com", new
UsernamePasswordCredentials(sLogin, sPassword));
       
        PostMethod authpost = new PostMethod("/ppsecure/post.srf");  
        authpost.setRequestHeader("User-Agent", "Mozilla/5.0 (X11; U;
Linux i686; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0");
      
      
        NameValuePair action   = new NameValuePair("sec", "rem");
        NameValuePair userid   = new NameValuePair("login", sLogin);
        NameValuePair password = new NameValuePair("passwd", sPassword);
        NameValuePair domain = new NameValuePair("domain",
"hotmail.com");
        NameValuePair lc = new NameValuePair("lc", "1033");
        NameValuePair id = new NameValuePair("id", "2");
        NameValuePair tw = new NameValuePair("tw", "20");
        NameValuePair fs = new NameValuePair("fs", "1");
        NameValuePair svc = new NameValuePair("svc", "mail");
        NameValuePair cbid = new NameValuePair("cbid", "24325");
        NameValuePair msppjph = new NameValuePair("msppjph", "1");
        NameValuePair kpp = new NameValuePair("kpp", "2");
        NameValuePair notinframe = new NameValuePair("notinframe", "1");
        //NameValuePair ru = new NameValuePair("ru", 
"http://www.hotmail.msn.com/cgi-bin/addresses");       
        NameValuePair da = new NameValuePair("da", "passport.com");
        NameValuePair submit1 =  new NameValuePair("submit1", " Sign In
");
      
        authpost.setRequestBody(new NameValuePair[] {action, userid,
password,lc,id,tw,fs,svc,cbid,msppjph,kpp,notinframe,da,submit1});
        //authpost.setQueryString(new NameValuePair[] {action, userid,
password});
       // authpost.setRequestBody(new NameValuePair[] {action, userid,
password,domain, notinframe});
        int status = client.executeMethod(authpost);
       
        System.out.println("\n");
        Header[] headers2 = authpost.getRequestHeaders();
        for(int i=0; i<headers2.length; i++) {
            Header h = headers2[i];
            System.out.println(h.getName()+" = "+ h.getValue());
        }
        System.out.println("\n");
        System.out.println("\nLogin form post: " +
authpost.getStatusLine().toString());
 
System.out.println("\nbody=\n"+authpost.getResponseBodyAsString());
Julius Davies wrote:

>Hi, Gamas,
>
>Try two things:
>
>1.)
>===============
>Set your "User-Agent" header on all your requests to one of the major 
>browsers.  This way if Hotmail is browser-sniffing, you can trick it.
>For example:
>
>User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) 
>Gecko/20050105 Debian/1.7.5-1
>
>2.)
>===============
>That reply you got back from Hotmail is a form of redirect.  The <HTML>

>you recieved is telling you to go here:
>
>http://login.passport.net/UICookiesDisabled.srf?rollrs=11
>
>
>yours,
>
>Julius
>
>On Fri, 2005-04-02 at 17:27 -0800, Gamas Sugiarto wrote:
>  
>
>>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=
>><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
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: 
>>httpclient-user-help@jakarta.apache.org
>>
>>    
>>
>
>  
>




---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
View raw message