I’m building a React app that talks to a Spring Boot backend. Both are running locally. When I try to send a POST request from React to my Spring Boot API, I get a CORS error. Here’s what I’m doing:
It appears the issue might be related to Spring Security. The 401 status code suggests an authentication problem. Have you configured Spring Security to allow unauthenticated access to your endpoints? You might need to add a security configuration class that permits all requests or specifically allows OPTIONS requests. Here’s a snippet that could help:
This configuration allows OPTIONS requests while maintaining security for other endpoints. Remember to adjust it according to your specific security requirements.
hey there, have u tried adding @CrossOrigin to ur controller methods? that worked for me. also, check if ur spring security config is blocking the OPTIONS request. sometimes it gets in the way. might need to allow OPTIONS requests explicitly. good luck!
hmm, interesting problem! have u considered using a proxy in ur React app? it could bypass the CORS issue entirely. What about ur server’s security settings? sometimes firewalls or antivirus can interfere. also, is ur backend definitely running on port 8085? just curious abt these aspects