This question is about charset and is NOT about content-type.
When I make a request to this page - https://www.baeldung.com/java-char-encoding, when I inspect the response, I can see the charset used for the response.
charset as utf-8
charset as utf-8
But when I make request to one of my internal server, i can not find charset info in response. no charset info
Knowing this info is important for me so I can set the encoding type of my HttpClient to same.
(As these are related Questions, I have ask them in one post. Thanks for understanding.)
The content-type application/json
has an assumed charset of UTF-8, as specified in RFC 8259.
There may be other well-known content types that have an assumed charset, but text/html
or text/javascript
are not among these, so it must always be specified.
This is why when you make a request that returns an HTML page or a JavaScript file the charset is specified, while when you make a request that returns JSON it is not.
For the cases where the charset is not assumed and it's not specified, then you have to guess, and likely the guess could be wrong, and you get garbled characters.
The charset does not depend on the HTTP protocol version.