为什么OKHttp禁止将某些可打印字符作为标题发送?我正在编写发布http标头的应用。由于a right single quoted character,应用崩溃了。
这是堆栈跟踪:
Fatal Exception: java.lang.IllegalArgumentException: Unexpected char 0x2019 at 358 in my-header value: test’s
at okhttp3.Headers.checkValue(Headers.java:272)
at okhttp3.Headers$Builder.add(Headers.java:312)
at okhttp3.Request$Builder.addHeader(Request.java:196)
...
这是引发异常的OkHttp source code:
internal fun checkValue(value: String, name: String) {
for (i in 0 until value.length) {
val c = value[i]
require(c == '\t' || c in '\u0020'..'\u007e') {
format("Unexpected char %#04x at %d in %s value: %s", c.toInt(), i, name, value)
}
}
}
看到该源代码,这是一种仅允许在HTTP标头中使用require(c == '\t' || c in '\u0020'..'\u007e')
范围内的字符的标准吗?