0

I get a HTTP/401 error when Axios send the preflight OPTIONS request. When I look to the OPTIONS request, I don't see any authentication headers, so the backend rejects it. The URL is protected by spring-security.

Client code:

axios.post('https://www.xxx.fr/blocage',
        { 'type': 'hvc' },
        {
            withCredentials: true,
            auth: {
                username: 'my_user',
                password: 'my_password'
            }
        }).then((response) => {
            console.log(response);
        }, (error) => {
            console.log(error);
        });

On the backend side (spring-boot 4), my controller:

@RestController
@CrossOrigin(origins = "*")
public class MyCalendarControler {
       @RequestMapping(value = "/blocage", 
            method = RequestMethod.POST,
            consumes = "application/json",
            produces = "application/json")
       public ResponseEntity<Object> createBlock(@RequestBody Block block) { ... }
...
}

Does someone have any idea ?

ThisaruG
  • 3,222
  • 7
  • 38
  • 60

0 Answers0