我一直在使用 RestTemplate 并且一直很满意!
但现在它糟透了。
我以前是这样做的:
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new GsonHttpMessageConverter());
restTemplate.put(URI, object);
通常我的服务器以 Ruby 方式接受 URL 中的格式:resource.json
但是现在我正在使用一个不再这样做的服务器。我需要使用 Header 来处理格式。
一切正常,restTemplate 将 content-type 设置为 application/json 但不要设置 Accept 标头。所以我的服务器发出 406 错误,因为默认格式是 HTML,而且他不呈现 html。
那么,是否有人有将内容和接受标头都放入 json 并添加 json 格式的正文的解决方法?