Announcement Announcement Module
Collapse
No announcement yet.
Resttemplate: Change accept header to application/json Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resttemplate: Change accept header to application/json

    How can I change a Accept-Header of a Resttemplate to application/json ?

    Code:
    RestTemplate restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new MappingJacksonHttpMessageConverter());
    converters.add(new StringHttpMessageConverter());
    converters.add(new FormHttpMessageConverter());
    restTemplate.setMessageConverters(converters);
    //parameters has type MultiValueMap<String, String>
    restTemplate.postForObject("http://localhost:8080/myrestapp/content", parameters, MultiValueMap.class);
    But the post header is allways:
    POST /apponizer-be/oauth/token HTTP/1.1
    Accept: application/x-www-form-urlencoded, multipart/form-data
    Content-Type: application/json;charset=UTF-8

    and my rest server responses with JSON. Depending on that I've got allways the following error:
    The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ()

  • #2
    it semas to be a bug. With the following code is the accept header ok:

    Code:
    RestTemplate restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    converters.add(new MappingJacksonHttpMessageConverter());
    restTemplate.setMessageConverters(converters);

    Comment

    Working...
    X