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

僤鯓⒐⒋嵵緔 提交于 2020-02-29 12:00:29

问题


When sending a Base64 encoded string as header using Http, I am getting error response as

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

Usage :

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


回答1:


0x0a is a newline character which is forbidden in a header. Solution would be to make sure that these characters are stripped off before sending the encoded value as header.

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



来源:https://stackoverflow.com/questions/43026163/unexpected-char-0x0a-in-header-value-when-using-okhttp-client-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!