title: Spring RestTemplate gives 401 Unauthorized error when sending with Authorization Header
body: <p>I am trying to hit one Microsoft Flow POST URL in my Spring Rest application using following code but it is giving me 401 error.
  My Code:</p>
  
  <pre><code>    @RequestMapping(value = "/hookslistner", method = RequestMethod.POST)
      public ResponseEntity&lt;Void&gt; recieveWebhook(@RequestBody InventorySystemModel inventory,
              @RequestHeader("event") String event,
              @RequestHeader("Authorization") String authorization) {
  // authorization = "Basic &lt;Base64 encoded value of username:pwd&gt;"
  
          RestTemplate restTemplate = new RestTemplate();
  
          org.springframework.http.HttpHeaders httpHeaders = new org.springframework.http.HttpHeaders();
  
          String url = "https://prod-01.centralindia.logic.azure.com/workflows/835348&lt;hiding rest of part&gt;";        
          String headerName = "Authorization";
          httpHeaders.add(headerName, authorization);
          httpHeaders.add("Content-Type", "application/json");
          HttpEntity&lt;String&gt; requestEntity = new HttpEntity&lt;&gt;("Headers", httpHeaders);
          System.out.println("&gt;&gt;&gt;&gt;&gt;&gt;&gt;" + restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class).getBody());
      }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>SEVERE: Servlet.service() for servlet [webhooks] in context with path [/inventoryhooks] threw exception [Request processing failed; nested exception is org.springframework.web.client.HttpClientErrorException: 401 Unauthorized] with root cause
  org.springframework.web.client.HttpClientErrorException: 401 Unauthorized
      at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
  .
  .
  .
  </code></pre>
  
  <p>Is it because my target url is https and my localhost is http?</p>
  
  <p>Can anyone point me what is going wrong?</p>