【发布时间】:2015-06-10 17:39:26
【问题描述】:
当我使用 Rest Template 时,从 Web 服务 quote(") 之一获取数据时以 (?) 的形式出现。我在邮递员中测试了 chrome 上的 Web 服务,它给出了正确的字符。我尝试编码 UTF-8,但没有成功。
我检查了以下是来自网络服务提供商的编码:
缓存控制 → 私有 连接→关闭 内容编码 → gzip 内容长度 → 3407 内容类型 → 文本/xml;字符集=ISO-8859-1 日期 → 2015 年 6 月 10 日星期三 13:35:53 GMT 服务器 → Google Search Appliance 变化 → 接受编码 X-Frame-Options → SAMEORIGIN x-content-type-options → nosniff x-xss-保护→1;模式=块
这是我的代码:
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
MediaType mediaType = new MediaType("text", "xml", Charset.forName("ISO-8859-1"));
headers.set("Accept", "text/xml; charset=ISO-8859-1");
headers.setContentType(mediaType);
headers.setAcceptCharset(Arrays.asList(Charset.forName("UTF-8")));
headers.setAccept(Arrays.asList(mediaType));
ResponseEntity<String> res = restTemplate.exchange(gsaSearchUrl, HttpMethod.GET, new HttpEntity<String>(headers), String.class);
System.out.println(res.getBody());
【问题讨论】:
标签: java encoding resttemplate