First, please do not name your PostMethod get variable.
Secondly, try the following:
PostMethod post = new PostMethod("yourUrl") { @Override public boolean getFollowRedirects() { return true; } };
If you ever found yourself on the βother sideβ and want your users not to be hurt, use the 303 (See Other) response code when redirecting the POST request to get instead of the usual 302 and 301 (for RFC ). Regular browsers are generally good, break the rules and DO NOT ask us to confirm these redirects, but many mobile browsers still do.
As for your question about forms-based authentication, you just need to find out the names of the parameters to use (for example, by looking at the source of the website on which you usually βlog inβ to the system) and then fill them with the appropriate values:
post.addParameter("username", username); post.addParameter("password", password);
I played with the login form at myoffice.bt.com, there are a few things in JavaScript.
The form is submitted https://myoffice.bt.com/siteminderagent/forms/login.fcc
The form elements that were submitted were as follows ( name=value , some values ββwere empty):
Segment=btb.hub SubSegment= searchType=0 searchPlatform=BEA lob=btb.hub queryText= searchText= ctl00$ masterWebpartManager$gwpCustomLogin1$CustomLogin1$UserName=your@ email.com ctl00$masterWebpartManager$gwpCustomLogin1$CustomLogin1$PWD=yourpwd ctl00$masterWebpartManager$gwpCustomLogin1$CustomLogin1$RememberMe=on USER=your@email.com PASSWORD=yourpwd SMENC=ISO-8859-1 SMLOCALE=US-EN userFirstLoginUrl=https://myoffice.bt.com/ManageBusinessApplications/SecretQA.aspx PrivateLoginSuccessUrl=https://myoffice.bt.com/sm/privatecreatesession.aspx?siteArea=btb.mya PublicLoginSuccessUrl=https://myoffice.bt.com/sm/createsession.aspx?siteArea=btb.mya target=https://myoffice.bt.com/sm/privatecreatesession.aspx?siteArea=btb.mya&TARGET=https%3a%2f%2fmyoffice.bt.com%2fdefault.aspx (hidden) submitStatus= smauthreason= smagentname= postpreservationdata= AnonUserName=anon@myoffice.bt.com authMode=SITEMINDER smUrl=https://myoffice.bt.com/siteminderagent/forms/login.fcc notSMUrl=https://myoffice.bt.com/default.aspx smIdentifier=1
Try adding some or all of them (at least USER and PASSWORD ) to your PostMethod and make sure that you submit the correct URL.
Lauri lehtinen
source share