SOLVED
Oddly, the problem was in the AUTHENTICATION
header.
I computed the header with the following code:
public setHeader(String code, String username)
{
StringBuilder sb = new StringBuilder(username);
sb.append(":");
sb.append(code);
sb = new StringBuilder(Base64.encodeToString(sb.toString().getBytes(), Base64.DEFAULT));
sb.insert(0, "Basic ");
auth = sb.toString();
}
The Base64.encodeToString()
method adds a \n
at the end of the line. .__.
By adding a trim()
in the last line, I threw away the new line and everything went fine in both 2.3.3 and 4 Android versions.