2017-08-30 74 views
0

我在服务器端代码有此(弹簧MVC):
@CrossOrigin(起源=“*”) @ControllerCORS在角度4

然而,当我尝试使用以角的请求4我收到以下错误:

XMLHttpRequest cannot load http://localhost:8081/newProject/updateTaskRemarks?goalSectionId=1002&goalSectionSupRemarks=yo . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://localhost:4200 ' is therefore not allowed access. The response had HTTP status code 403.

+0

有没有在你的Web控制台其他任何错误的错误已被包括在WebSecurityConfigurerAdapter以下行解决? – Gab

+1

*“响应中有HTTP状态码403”*表示真正的问题是身份验证失败。您看到CORS错误信息的唯一原因是许多服务器通常不会将Access-Control-Allow-Origin头添加到错误响应中,而只是将它们添加到成功响应中(例如200 OK)。所以你需要弄清楚并解决的问题是为什么你的请求会导致认证失败。 – sideshowbarker

+0

@ GabrieleB-David没有其他错误。 – HBK

回答

0

感谢您的回复。 http.authorizeRequests().antMatchers("/").permitAll().and() .csrf().disable();