Please check maxRedirection. 
It should be the max numbers of redirections, but passing a value of 2 resulting in 3 redirections. I suggest you to change the condition <code> if (maxRedirection >= 0)</code> to <code>if (maxRedirection > 0)</code> and call getResponse with a value of 3 for the redirection parameter.