我正在尝试使用 Spring Integration 从网络加载多语言 XML 文件。不幸的是,Spring Integration 似乎将其视为其他形式的编码。这是我的配置的相关部分:
<int-http:outbound-gateway id="example"
request-channel="requests"
url="http://localhost/test.xml"
http-method="GET"
expected-response-type="java.lang.String"
charset="UTF-8"
reply-timeout="1234"
reply-channel="replies"/>
我检索到的文本被视为 ISO-8859-1。我之所以相信这一点,是因为如果我重新编码然后解码,我就会得到正确的文本。像这样的事情:
public void handleReply(String rawXML) {
String forRealzies = "";
try {
String hack1 = URLEncoder.encode(rawXML, "ISO-8859-1");
forRealzies = URLDecoder.decode(hack1, "UTF-8");
} catch(UnsupportedEncodingException e1) {
e1.printStackTrace();
}
// forRealzies now has the properly encoded String
}
我真的希望我在 XML 配置中做错了什么。有什么建议吗?
最佳答案
您应该在内容类型
上设置字符集
;请参阅here .
关于java - Spring Integration http 出站网关和 UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25466127/