Greetings,
I know this isn't a core package but wanted to ask here anyway in the hopes that maybe someone has had some experience with it. I am trying to make a program to do basic form authentication, and then after logging in, access a login protected page. I created a simple login form + php session protected page to test the app, and the app can access the protected page as expected if I supply the correct username/password (and likewise does not work if I do not supply the correct login info). However, when I try to use it for real and point it to my phpbb forum, I can't get past the login page (I am passing the correct form values), httpclient handles the cookie management auto magically so i'm not sure whats going on there other then I can echo them out and see that I am receiving cookies on each page hit (likewise I am not 100% familiar with how phpbb forum login process works, just working off the form html atm). Here is my code, I have tried it without success using every cookie specification, any ideas welcome...I think the next step if I can't get this to work I guess is to just build it with java.net and handle post/cookies manually though idealy id like to stick with the httpclient
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
public class LoginTest
{
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
GetMethod getPage = new GetMethod("http://website/login.php?mode=login");
client.executeMethod(getPage);
//client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
//Login page
PostMethod postLogin = new PostMethod("http://website/login.php?mode=login");
NameValuePair[] data = {
new NameValuePair("username" , "joesmith"),
new NameValuePair("password", "foobar")
};
postLogin.setRequestBody(data);
client.executeMethod(postLogin);
//this is a request to a page that requires authentication
GetMethod getPage2 = new GetMethod("http://website/protected/page.php");
client.executeMethod(getPage2);
System.out.println(getPage2.getResponseBodyAsString());
}
}