I am using vue in the front end and spring boot in the back end .
I have used axios to make server call from the vue code .
Every thing was fine with GET ,POST requests.
When i try to make DELETE request it failed with
403
status and the error response isInvalid CROS request
.But the same
DELETE
request works In POSTMAN
I have tried the following solution mentioned in the another post and it didn't help me 1. added withCredentials: true in the request header
- added headers: {'X-Requested-With': 'XMLHttpRequest','X-CSRFToken': 'your token here'}
3.added @CrossOrigin annotation in the DELETE
api
This is how i created axios instance
const token = localStorage.token;
const instance = axios.create({
baseURL: "/",
headers: {
Authorization: token
}
});
making request as below
instance.delete(`/user/${username}`);
It throws 403
Invalid CROS Request
as response and its not hitting the server api too
@CrossOrigin(origins = "http://localhost:8080") @DeleteMapping("/{username}") @ResponseStatus(HttpStatus.NO_CONTENT) public void deleteUserByUsername(@PathVariable("username") String username) { User user= userRepository.findByUsername(username); userRepository.delete(user); }
origins - client URL which request from the server – Saradha