title: Spring RestTemplate receives "401 Unauthorized"
body: <p>I am using the following to retrieve JSON via RestTemplate in Spring 4:</p>
  
  <pre><code>protected DocInfoResponse retrieveData(String urlWithAuth) {
      RestTemplate restTemplate = new RestTemplate();
      HttpHeaders headers = new HttpHeaders();
      headers.add("Authorization", "Basic " + auth.getSig());
      HttpEntity&lt;String&gt; request = new HttpEntity&lt;String&gt;(headers);
      ResponseEntity&lt;DocInfoResponse&gt; response = restTemplate.exchange(urlWithAuth, HttpMethod.GET, request, DocInfoResponse.class);
      return response.getBody();
  }
  </code></pre>
  
  <p>I used the same code (with different response class) to successfully get a JSON doc from the same site (with different parameters to get a different doc).</p>
  
  <p>When I execute the above code I receive the following stack trace (in part):</p>
  
  <pre><code>Caused by: org.springframework.web.client.HttpClientErrorException: 401 Unauthorized 
  at 
  org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
  </code></pre>
  
  <p>Can anyone point me to why this might be receiving the exception?</p>