Unexpected char 0x0a in header value when using OkHttp client in Android(在 Android 中使用 OkHttp 客户端时,标头值中出现意外的 char 0x0a)
问题描述
使用 Http 发送 Base64 编码字符串作为标头时,我收到错误响应
When sending a Base64 encoded string as header using Http, I am getting error response as
标头值中 28 处的意外字符 0x0a:I99Uy+HjG5PpEhmi8vZgm0W7KDQ=
用法:
String encodedHeader = Base64.encodeToString(value.getBytes(), Base64.DEFAULT);header.put("auth", encodedHeader);
推荐答案
0x0a 是一个换行符,在标题中是被禁止的.解决方案是确保在将编码值作为标头发送之前删除这些字符.
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);这样可以避免使用特定于平台的换行符换行.
Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
this avoids wrapping with a platform specific newline character(s).
这篇关于在 Android 中使用 OkHttp 客户端时,标头值中出现意外的 char 0x0a的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Android 中使用 OkHttp 客户端时,标头值中出现意外的 char 0x0a
基础教程推荐
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
