title: CORS error on Axios PUT request from React to Spring API
body: <p>I am working on an update functionality using PUT. I have a React front end and Spring back-end API. Here is the following PUT request made from front-end:</p>
  
  <pre><code>updateStuff(username, id, stuff){
      return Axios.put(`http://localhost:8080/stuff/${username}`, {stuff})
  }
  </code></pre>
  
  <p>Controller to handle this request:</p>
  
  <pre><code>@RestController
  @CrossOrigin(origins="http://localhost:3000")
  public class StuffController {
  
          @Autowired
          private StuffService stuffService;
  
      @PutMapping(path="/stuff/{username}/{id}")
      public ResponseEntity&lt;Stuff&gt; updateStuff(@PathVariable String username,
                     @PathVariable long id, 
                     @RequestBody Stuff stuff) {
      Stuff response =  stuffService.save(stuff);
      return new ResponseEntity&lt;Stuff&gt;(stuff, HttpStatus.OK);
  }
  </code></pre>
  
  <p>I am able to use the same service for GET and DELETE. I am also able to send request using REST client. But when I am trying using browser I am getting this error in console:</p>
  
  <pre><code>Access to XMLHttpRequest at 'http://localhost:8080/stuff/abc' from origin
  'http://localhost:3000' has been blocked by CORS policy: 
   Response to preflight request doesn't pass access control check: No 'Access- 
   Control-Allow-Origin' header is present on the requested resource.
  
  PUT http://localhost:8080/stuff/abc net::ERR_FAILED
  </code></pre>
  
  <p>Not able to figure out why its just happening for PUT request? How to resolve this? Appreciate your help and time!</p>
  
  <p>EDIT:
  Updated the front-end to:</p>
  
  <pre><code>    updateStuff(username, id, stuff){
      return Axios.put(`http://localhost:8080/stuff/${username}`,             {
              headers:{
                  'Access-Control-Allow-Origin':'*',
                  'Content-Type': 'application/json;charset=UTF-8',
              }
          })
      }
  </code></pre>
  
  <p>Still its throwing the same error. So far Spring Security is not configured. I am just checking a simple update flow without any authentication or authorization.</p>
  
  <p>EDIT 2: Request headers in browser has Access-Control-Allow-Origin: *:
  <a href="https://i.stack.imgur.com/EH0i3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EH0i3.png" alt="enter image description here"></a></p>