commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "enrico200165@tiscali.it" <enrico200...@tiscali.it>
Subject HttpClient - After POST I get ONLY the <HEAD> of the response, no <BODY>
Date Fri, 10 Feb 2006 08:04:00 GMT

I am trying to perform a login  by POSTing, I am using a JAPANES to 
test site (mixi.jp)
the login seems to be successful, I get
Login form post: HTTP/1.1 200 OK

When I get the reponse by reading from the stream got this way: 
  InputStream istream = authpost.getResponseBodyAsStream();

I get only the text below (the spurious characters before <head> are 
always present.)
¥Ç¡¼¥¿¤Ï¤¢¤ê¤Þ¤»¤ó¡£<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=EUC-JP">
<META name="description" lang="ja" content="mixi(¥ß¥¯¥·¥£)¤Ï¡¢¤³¤ì¤Þ¤Ç
¤Îͧ¿Í´Ø·¸¤ò¹¹¤ËÁÇŨ¤Ê¤â¤Î¤Ø¤ÈƳ¤­¡¢¿·¤·¤¤¸òή¤âÀ¸¤ß½Ð¤¹ÆüËܽé¤Î¥³¥ß¥å¥Ë
¥Æ¥£¥¨¥ó¥¿¡¼¥Æ¥¤¥á¥ó¥È¡¦¥½¡¼¥·¥ã¥ë¥Í¥Ã¥È¥ï¡¼¥­¥ó¥°¥µ¥¤¥È¤Ç¤¹¡£">

<title>¥½¡¼¥·¥ã¥ë¡¦¥Í¥Ã¥È¥ï¡¼¥­¥ó¥°¥µ¥¤¥È [mixi(¥ß¥¯¥·¥£)]</title>
<script language="javascript" type="text/javascript" src="http://mixi.
jp/mixi3.js"></script>
<link REL=STYLESHEET HREF="http://mixi.jp/mixi.css" TYPE="TEXT/CSS">
</head>

I include most of the code I use (some set... instructions are 
omitted because in a separate method,)


PrepareConnection();  // my method, with initializations
        
        // See if we got any cookies
        CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
        Cookie[] initcookies = cookiespec.match(
                Costanti.LOGON_SITE, Costanti.LOGON_PORT, "/", false, 
client.getState().getCookies());
        System.out.println("Initial set of cookies:");
        if (initcookies.length == 0) {
            System.out.println("None");
        } else {
            for (int i = 0; i < initcookies.length; i++) {
                System.out.println("- " + initcookies[i].toString());
            }
        }
        
        PostMethod authpost = new PostMethod(Costanti.LOGON_SITE);
        NameValuePair action   = new NameValuePair("action", "login.
pl");
        NameValuePair urlvp      = new NameValuePair("next_url", 
"/home.pl");
        NameValuePair userid   = new NameValuePair("email", 
"removed"); // this is the user ID
        NameValuePair password = new NameValuePair("password", 
"removed");
        
        
        //execute the method
        authpost.setRequestBody( new NameValuePair[] {action, urlvp, 
userid, password});
        try {
            client.executeMethod(authpost);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        
        InputStream istream = authpost.getResponseBodyAsStream();  // 
authpost.getResponseBodyAsStream();
        new PageTracer().ConsolePrintPageContent(istream);
        
        System.out.println("Login form post: " + authpost.
getStatusLine().toString());
        
        authpost.releaseConnection();
        
        // Usually a successful form-based login results in a 
redicrect to another url
        int statuscode = authpost.getStatusCode();
        if (HttpStatus.SC_OK != statuscode) System.out.println
("HttpStatus not OK, = " + statuscode );
        else System.out.println("HttpStatus OK, bene, !!!!  = " + 
statuscode );
        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);
                GetMethod  redirect = new GetMethod(newuri);
                try {                    
                    client.executeMethod(redirect);
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                System.out.println("Redirect: " + redirect.
getStatusLine().toString());
                redirect.releaseConnection();
            } else {
                System.out.println("Invalid redirect");
                System.exit(1);
            }
        }






		
Tiscali ADSL 4 Mega Flat
Naviga senza limiti con l'unica Adsl a 4 Mega di velocità a soli 19,95 € al mese!
Attivala subito e hai GRATIS 2 MESI e l'ATTIVAZIONE. 
http://abbonati.tiscali.it/adsl/sa/4flat_tc/

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


Mime
View raw message