// check for post redirect as post redirects are not handled
// automatically
// RFC2616 (10.3 Redirection 3xx).
// The second request (forwarded method) can only be a GET or HEAD.
Header locationHeader = response.getFirstHeader("location");
if(locationHeader != null
&& req instanceof HttpPost
&& (response.getStatusLine().getStatusCode()
== HttpStatus.SC_MOVED_PERMANENTLY
|| response.getStatusLine().getStatusCode()
== HttpStatus.SC_MOVED_TEMPORARILY
|| response.getStatusLine().getStatusCode()
== HttpStatus.SC_SEE_OTHER)
&& redirects < MAX_REDIRECTS)
{
HttpRequestBase oldreq = req;
oldreq.abort();
String newLocation = locationHeader.getValue();
// append query string if any
HttpEntity en = ((HttpPost) oldreq).getEntity();
if(en != null && en instanceof StringEntity)
{