commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ballard, Margaret" <Margaret.Ball...@planethome.com>
Subject AW: http-client Post Redirect
Date Fri, 14 Mar 2003 16:56:14 GMT
I made a comment mistake in the code I posted.  The error occurs
right before where I marked it, in this line:

status = client.executeMethod(new GetMethod(redirect));

That's where I get a 405 Status, and I don't understand why.

-----Ursprüngliche Nachricht-----
Von: Ballard, Margaret 
Gesendet: Freitag, 14. März 2003 14:39
An: commons-user@jakarta.apache.org
Betreff: http-client Post Redirect


Hello all,
 
I am trying to emulate logging into a web page in code.  I am going
through a proxy, and using ssl.  The page, after a successful login,
redirects to a new page.  I know that followRedirects is disabled for
post, so I find out where it's trying to redirect to, and make that
redirect myself by making a getmethod to the redirect url.  I get a 405
Method not allowed Status code as a result, even though get is listed as
an allowed method in the response header. 
 
What step am I missing?  Is there another way to handle a post redirect?
 
Code:
    public static void main(String[] args) throws Exception {
        HttpClient client = new HttpClient();
        .
        .
        .
        client.getHostConfiguration().setProxy("ourproxy", 8080);
        HttpState state = new HttpState();
        state.setProxyCredentials("realm",new
UsernamePasswordCredentials("proxyname","proxypassword"));
        client.setState(state);
        
        String _uri = "
https://secure.planethome.de/myplanet/login.jsp";
        GetMethod method = new GetMethod(_uri);
 
        int status = client.executeMethod(method);
 
        PostMethod postmethod = new PostMethod(_uri);
        
        // Add Request Body
        NameValuePair[] params = new NameValuePair[4];
        params[0] = new NameValuePair("hidden", "yes");
        params[1] = new NameValuePair("username", "username");
        params[2] = new NameValuePair("password", "password");
        params[3] = new NameValuePair("request", "login");
        postmethod.setRequestBody(params);
        
        // Execute Post
        status = client.executeMethod(postmethod);
 
        System.out.println("Status: " + status);  
        
        // Returns a Status Code 100, so I resubmit
        postmethod.recycle();
        status = client.executeMethod(postmethod);
        
        // This time, it returns a Status Code 302 Redirect,
        // so I find where it's redirecting to, and send a Get
        Header location = postmethod.getResponseHeader("Location");
        String redirect = location.getValue();
        GetMethod redirectmethod = new GetMethod(redirect);
        status = client.executeMethod(new GetMethod(redirect));
 
 // Here's my problem - it returns a 405 Method not allowed
 // code.  But Get is listed as an Allowed Method in the Response Header
        result = postmethod.getResponseBodyAsString();
        
    }
 
 
Any help greatly appreciated!!
 
Margaret Ballard
 

Mime
View raw message