Encoding/Content-Type 丹麦字母“æ”的问题

Encoding/Content-Type issue with Danish letters "æ"

我在对来自 HTTP REST 响应的丹麦语字母进行编码时遇到问题。

当我调用 REST 服务时,我得到 "bev�ge",它必须是 "bevæge",Chrome 浏览器对其进行编码并给我预期的字母 "bevæge",但是当我阅读 Java API 的回复时,我得到了 "bev�ge",有人能帮我解决这个问题吗,我将不胜感激,

提前致谢

您的编码似乎不匹配

考虑

    String str = "bevæge";

    byte[] b = str.getBytes();

    try {
        System.out.println(new String (b, "US-ASCII"));
        System.out.println(new String (b, "UTF8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

输出将是

bev��ge
bevæge

看起来,如果字符串被传输为 ISO8859-1

尝试以下::

String str = "bevæge";

byte[] b = str.getBytes();

try {
    System.out.println(new String (b, "ISO8859-1"));
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
}

将输出

bevæge

在您的 HttpClient 中,尝试添加以下内容 header: Accept-charset: UTF-8