3.2. Header Fields
Each header field consists of a case-insensitive field name followed
by a colon (":"), optional leading whitespace, the field value, and
optional trailing whitespace.
header-field = field-name ":" OWS field-value OWS
field-name = token
field-value = *( field-content / obs-fold )
field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
field-vchar = VCHAR / obs-text
; VCHAR (any visible [USASCII] character)
obs-fold = CRLF 1*( SP / HTAB )
; obsolete line folding
; see Section 3.2.4
OWS = *( SP / HTAB )
; HTAB (horizontal tab)
; SP (space)
obs-text = %x80-FF
The field-name token labels the corresponding field-value as having
the semantics defined by that header field. For example, the Date
header field is defined in Section 7.1.1.2 of [RFC7231] as containing
the origination timestamp for the message in which it appears.
위의 사양에서 필드 값은 특정 http 클라이언트에 해당하는 ASCII로 표시되는 문자여야 한다는 것을 알 수 있습니다(예: okhttp에서 이러한 확인):
값을 판단할 때, 값의 문자 집합은 0x20-0x7E 사이여야 하며, 이는 ASCII 가시 문자 범위에 해당합니다! 결국 문제 시나리오 자체로 돌아가서 비계의 빨간색 상자에 줄이 추가되어 발생한 문제라는 것을 발견했습니다:
그런 다음 다음 코드를 사용하여 ASCII가 아닌 문자를 쉽게 처리할 수 있습니다:
// 문자셋은 유효한 모든 문자셋을 사용할 수 있으므로 다시 한 번 확인하세요.
// %E4%B8%AD%E6%96%87
URLEncoder.encode("", "UTF-8")
기본 구성 요소를 작성할 때는 호환성 문제에 특별한 주의를 기울여야 합니다. 문자 집합 코드에서 예기치 않은 문제를 피하려면 ASCII/BASE64 인코딩을 수행하는 것이 좋습니다!





