Unexpected char 0x0a in header value when using OkHttp client in Android

When sending Base64 lowercase encoding as a header using Http, I get an error like

Unexpected char 0x0a at 28 in header value: I99Uy+HjG5PpEhmi8vZgm0W7KDQ=

Using:

String encodedHeader = Base64.encodeToString(value.getBytes(), Base64.DEFAULT); header.put("auth", encodedHeader);

+7
java android base64 retrofit
source share
1 answer

0x0a - a newline character that is prohibited in the header. The solution should be to remove these characters before sending the encoded value as a header.

Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP); this avoids wrapping a newline with a newline.

+13
source

All Articles