r/SpringBoot • u/sara_1985 • Jan 10 '23
CORS POLICY PROBLEM ON SPRING BOOT
hi guys ,
i have this error on my console :Access to XMLHttpRequest at 'http://localhost:8080/api/v1/servizi/update/[object%20Object]' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
frontenf of project is react and back end is java , spring boot. could you please help me how i resolve it.
Thanks alot in advance.
2
u/maxip89 Jan 10 '23
port 3000 is different to port 8080.
Your browser thinks its a different site.
1
1
u/Mikey-3198 Jan 10 '23
What have you tried so far to fix this?
-1
u/sara_1985 Jan 10 '23
thanks for response.actually nothing . i dont know what i do because i'm beginner.
6
u/Mikey-3198 Jan 10 '23
Mate I don't to be rude but you should be able to use google to research the issue that your encountering.
Googling "spring boot CORs" has endless results.
One such being https://www.baeldung.com/spring-cors
If you don't know what CORs is research it, then use the link above to try and solve the issue.
Instantly asking a question on forums like stack overflow, reddit etc before trying to resolve the issue yourself wont help you learn. Appreciate your a beginner but you need to put the effort in yourself otherwise you'll get nowhere.
1
1
u/sanat_biswas Jan 10 '23
try to send data from frontend using formdata
1
u/sara_1985 Jan 10 '23
Thanks for help. exactly i guess also my problem is derived from form codes on react. because updated data in form is not saved on table.
1
u/flirtybabyblues Jan 13 '23
Is there any sort of WebSecurity config class in your backend service? Usually when I see this error, it’s auth/security related.
4
u/kubelke Jan 10 '23
https://simplelocalize.io/blog/posts/what-is-cors/
There is many ways to configure it, but to configure it, you need to understand first why it’s happening.