Being new to the v4.x HttpClient (and rusty with older versions...ack), this
may be something obvious that I've just missed.
The tutorial (section 5.3) states that HttpClient handles most redirect
automatically. I have the following set:
httpclient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,
true);
httpclient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS,
true);
I create the HttpPost for the form POST which seems to be working:
post = new HttpPost(baseUrl + "/userLoginManual.aspx");
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add(new BasicNameValuePair("postlogin_path",
"/offers/consent.aspx"));
formparams.add(new BasicNameValuePair("login", username));
formparams.add(new BasicNameValuePair("password", password));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams,
"UTF-8");
post.setEntity(entity);
response = httpclient.execute(post, localContext);
code = response.getStatusLine().getStatusCode();
But the response is "302 - Moved Temporarily". This is part of the normal
process, but I would have expected HttpClient to handle it and return me a
200.
Since I really only needed the cookies returned after successful auth, I am
doing :
try {
respStr = responseHandler.handleResponse(response);
} catch (HttpResponseException hrex) {
post.abort();
}
in order to consume the response which is throwing the HttpResponseException
(due to the 302) and calling post.abort(). This works for me, but I
wondered why the redirect isn't happening automagically.
Any light/knowledge/insight is much appreciated.
--
Jeff Vincent
[email protected]
See my LinkedIn profile at:
http://www.linkedin.com/in/rjeffreyvincent
I ♥ DropBox <http://db.tt/9O6LfBX> !!