title: HttpClientErrorException$BadRequest: 400 : [no body] when calling restTemplate.postForObject
body: <p>I am calling a POST service <strong>getOrder3</strong> written in SpringBoot which is working fine (tested in Postman), but getting error when called via restTemplate.postForObject from another service. I tried 2 versions of the client service <strong>getOrderClient</strong> and <strong>getOrderClient2</strong>, but both are giving same error :</p>
  
  <p><strong>HttpClientErrorException$BadRequest: 400 : [no body]</strong></p>
  
  <p>Please find the details below. Any help is appreciated.</p>
  
  <p><strong>getOrder3</strong></p>
  
  <pre><code>@PostMapping(value="/getOrder3/{month}",produces="application/json")
      public ResponseEntity&lt;OrderResponse&gt; getOrder3(
          @PathVariable("month") String month,
          @RequestParam String parmRequestSource,
          @RequestParam(required=false) String parmAudienceType,
          @RequestBody OrderRequestForm orderRequestForm) {
  
          OrderResponse orderResponse = new OrderResponse();
  
          log.info("In getOrder3...parmRequestSource = " + parmRequestSource + " parmAudienceType = " + parmAudienceType);
  
              try {
  
                      //validate JSON schema
                      //orderService.validateMessageAgainstJSONSchema(orderRequestForm);
  
                      //process order
                      orderResponse = orderService.processOrder(orderRequestForm);
  
                      orderResponse.setParmRequestSource(parmRequestSource);
                      orderResponse.setParmAudienceType(parmAudienceType);
                      orderResponse.setMonth(month);
  
  
              }catch (Exception e) {
                  throw new OrderException("101", e.getMessage(), HttpStatus.BAD_REQUEST);
              }   
  
          return new ResponseEntity&lt;&gt;(orderResponse,HttpStatus.OK);
      }
  </code></pre>
  
  <p>The service is working fine , tested in postman</p>
  
  <p><a href="https://i.stack.imgur.com/Dajtv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dajtv.png" alt="enter image description here"></a></p>
  
  <p>Now when I try to call via another microservice via restTemplate.postForObject, I get the error. Tried 2 versions of the client as below, <strong>getOrderClient</strong> and <strong>getOrderClient2</strong></p>
  
  <p><strong>getOrderClient</strong></p>
  
  <pre><code>@PostMapping(value="/getOrderClient/{month}",produces="application/json")
      public OrderResponse getOrderClient(
              @PathVariable("month") String month,
              @RequestParam String parmRequestSource,
              @RequestParam String parmAudienceType,
              @RequestBody OrderRequestForm orderRequestForm) throws URISyntaxException, JsonProcessingException {
          RestTemplate restTemplate = new RestTemplate();
  
          URI uri = new URI("http://localhost:51001/orders/v1/getOrder/"+month+"?parmRequestSource="+parmRequestSource+"&amp;parmAudienceType="+parmAudienceType);
          HttpHeaders headers = new HttpHeaders();
          headers.setContentType(MediaType.APPLICATION_JSON);
  
          String requestJson  = new ObjectMapper().writeValueAsString(orderRequestForm);
  
          HttpEntity&lt;String&gt; httpEntity = new HttpEntity&lt;String&gt;(requestJson,headers);
          String response =  restTemplate.postForObject(uri, httpEntity, String.class);
  
          return new ObjectMapper().readValue(response, OrderResponse.class);
      }
  
  </code></pre>
  
  <p><strong>getOrderClient2</strong></p>
  
  <pre><code>@PostMapping(value="/getOrderClient2/{month}",produces="application/json")
          public OrderResponse getOrderClient2(
                  @PathVariable("month") String month,
                  @RequestParam String parmRequestSource,
                  @RequestParam String parmAudienceType,
                  @RequestBody OrderRequestForm orderRequestForm) throws URISyntaxException, JsonProcessingException {
              RestTemplate restTemplate = new RestTemplate();
  
              URI uri = new URI("http://localhost:51001/orders/v1/getOrder/"+month+"?parmRequestSource="+parmRequestSource+"&amp;parmAudienceType="+parmAudienceType);
  
              return restTemplate.postForObject(uri, orderRequestForm, OrderResponse.class);
          }
  </code></pre>
  
  <p>Both are giving same error :</p>
  
  <p><strong>HttpClientErrorException$BadRequest: 400 : [no body]</strong></p>
  
  <p>Please suggest.</p>