title: How do I read HTTP status code from RestTemplate?
body: <p>I call Rest API using RestTemplate. Response don't has any issues.I need to get HTTP status code Like this.</p>
  <blockquote>
  <p>Request is ok- 200</p>
  <p>Unauthorized - 400</p>
  </blockquote>
  <p>According to many post I met bellow answer.</p>
  <pre><code>RestTemplate template = new RestTemplate();
  HttpEntity&lt;String&gt; response = template.exchange(url, HttpMethod.POST, request, String.class);
  
  String resultString = response.getBody();
  HttpHeaders headers = response.getHeaders();
  </code></pre>
  <p>In here used exchange method to get response.(template.exchange....)
  But I used</p>
  <blockquote>
  <p>postForObject method</p>
  </blockquote>
  <p>This is my code</p>
  <pre><code>public BalanceCheckResponse accountTotal(String counterAlias, String counterAuth, String subscriberType,
          String subscriberValue, String accessMode, String token) {
      
      BalanceCheckResponse objResponse = new BalanceCheckResponse();
  
      try {
          
          BalanceCheckRequest objRequest = new BalanceCheckRequest();
          objRequest.setCounterAlias(counterAlias);
          objRequest.setCounterAuth(counterAuth);
          objRequest.setSubscriberType(subscriberType);
          objRequest.setSubscriberValue(subscriberValue);
          objRequest.setAccessMode(accessMode);
  
          RestTemplate rstTemp = new RestTemplate();
          final String url = &quot;https://ideabiz.lk/apicall/startpoint/v1/balanceCheck&quot;;
          List&lt;HttpMessageConverter&lt;?&gt;&gt; messageConverters = new ArrayList&lt;HttpMessageConverter&lt;?&gt;&gt;();
          MappingJackson2HttpMessageConverter map =new MappingJackson2HttpMessageConverter();
          messageConverters.add(map);
          //messageConverters.add(new StringHttpMessageConverter());
          rstTemp.setMessageConverters(messageConverters);
  
          HttpHeaders headers = new HttpHeaders();
          headers.setContentType(MediaType.APPLICATION_JSON);
          headers.add(&quot;Authorization&quot;, &quot;Bearer &quot;+token);
  
          HttpEntity&lt;BalanceCheckRequest&gt; entity = new HttpEntity&lt;BalanceCheckRequest&gt;(objRequest,headers);
          objResponse = rstTemp.postForObject(url,entity, BalanceCheckResponse.class  );
          
          
      } catch (Exception e) {
          e.printStackTrace();
      }
      System.out.println(objResponse.getCurrentBalance());
      return objResponse;
  
  }
  </code></pre>
  <p>In my code</p>
  <blockquote>
  <p>objResponse.getHeaders();</p>
  </blockquote>
  <p>show error. What can I do in here. Do you have idea?</p>