简体   繁体   中英

Spring RestTemplate post object not not sending in request?

I am consuming a web service using RestTemplate and my POST request is as follows.

   String url = "http://192.168.1.3:9200/_search";

RestTemplate requestTemplate = new RestTemplate();

    MappingJackson2HttpMessageConverter jsonHttpMessageConverter = new MappingJackson2HttpMessageConverter();
            jsonHttpMessageConverter.getObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

            requestTemplate.getMessageConverters().add(jsonHttpMessageConverter);
    String uuidResult = requestTemplate.postForObject(url, requestBodyJsonObject ,
                    String.class);

I tried printing my requestBodyJsonObject and put it in a rest client, it works fine so no issue with request body. But here I am not getting the expected result and just getting the result when I send a post request without a request body from rest client.

So I am clueless here. Your help would be highly appreciated.

call simple like this, dont add

MappingJackson2HttpMessageConverter jsonHttpMessageConverter = new MappingJackson2HttpMessageConverter();

with rest template jsonHttpMessageConverter.getObjectMapper().configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);

Sample :

RestTemplate requestTemplate = new RestTemplate();
    Login responseEntity=null;
            try {
                 responseEntity = restTemplate.postForObject("/http:localhost:8080/login", login,
                        Login.class);
            } catch (Exception e) {
            }
            return responseEntity;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM