Veena,

The code you are using is almost a verbatim copy of the form login demo
application that comes with HttpClient. I see nothing wrong with it. If
you expect us to help you, you have to produce a wire/context log of the
HTTP session that exhibits the problem and post it to this list

See the logging guide for details:
<http://jakarta.apache.org/commons/httpclient/logging.html>

Oleg

On Tue, 2005-03-01 at 19:16 +0530, Veena Sarolkar wrote:
> Hi,
> 
> I have read the complete documentation of HttpClient.
> I am using it as an application not a web application so can't send the log.
> I am just sending the code I tried...
> 
> 
> public class PostTry {
> 
>   /**
>    * Constructor for BasicAuthenticatonExample.
>    */
>   public PostTry() {
>     super();
>   }
> 
>   public static void main(String[] args) throws Exception {
>     System.setProperty("java.protocol.handler.pkgs",
> "com.sun.net.ssl.internal.www.protocol");
>     Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
> 
>     // create a GET method that reads a file over HTTPS, we're assuming
>     // that this file requires basic authentication using the realm above.
>     PostMethod post = new PostMethod("https://gna.org/account/login.php";);
> 
> 
>     post.setDoAuthentication( true );
>     post.setFollowRedirects(false) ;
> 
>     NameValuePair form_loginname= new NameValuePair("form_loginname",
> "veena");
>     NameValuePair form_pw= new NameValuePair("form_pw", "veena");
>     NameValuePair stay_in_ssl= new NameValuePair("stay_in_ssl", "1");
>     NameValuePair cookie_for_a_year= new NameValuePair("cookie_for_a_year",
> "0");
>     NameValuePair login= new NameValuePair("login", "login");
>     post.setRequestBody(
>         new NameValuePair[] {form_loginname, form_pw, stay_in_ssl,
> cookie_for_a_year,login});
> 
>     client.executeMethod(post);
>     System.out.println("Login form post: " +
> post.getStatusLine().toString());
> 
>     post.releaseConnection();
>     // See if we got any cookies
>     // The only way of telling whether logon succeeded is
>     // by finding a session cookie
>     client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
>     CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
>     Cookie[] logoncookies = cookiespec.match(
>         "gna.org", 443, "/", false, client.getState().getCookies());
>     System.out.println("Logon cookies:");
>     if (logoncookies.length == 0) {
>       System.out.println("None");
>     }
>     else
>     {
>       for (int i = 0; i < logoncookies.length; i++) {
> 
>         System.out.println("- " + logoncookies[i].toString());
>       }
>     }
> 
>     int statuscode = post.getStatusCode();
>     if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) ||
>         (statuscode == HttpStatus.SC_MOVED_PERMANENTLY) ||
>         (statuscode == HttpStatus.SC_SEE_OTHER) ||
>         (statuscode == HttpStatus.SC_TEMPORARY_REDIRECT))
>     {
>       Header header = post.getResponseHeader("location");
>       post.getResponseBodyAsString();
> 
>       post.releaseConnection();
>       if (header != null)
>       {
>         String newuri = header.getValue();
>         if ((newuri == null) || (newuri.equals("")))
>         {
>           newuri = "/";
>         }
>         System.out.println("Redirect target: " + newuri);
>         GetMethod redirect = new GetMethod(newuri);
> 
>         logoncookies = cookiespec.match(
>             "gna.org", 443, "/my", false, client.getState().getCookies());
> 
>         System.out.println("Logon cookies:");
>         if (logoncookies.length == 0) {
>           System.out.println("None");
>         }
>         else
>         {
>           for (int i = 0; i < logoncookies.length; i++) {
> 
>             System.out.println("- " + logoncookies[i].toString());
>           }
>         }
> 
>         client.executeMethod(redirect);
> 
>         System.out.println("response :"+redirect.getStatusLine());
>         System.out.println("response :"+redirect.getResponseBodyAsString());
> 
>         // release any connection resources used by the method
>         redirect.releaseConnection();
>       }
>       else
>       {
>         System.out.println("Invalid redirect");
>         System.exit(1);
>       }
>     }
>   }
> }
> 
> It is giving me proper set of cookies for original as well as redirected
> urls.
> But it is not giving the page next to login but still giving the original
> page in the response.
> Am I missing something?
> 
> Veena
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to