I am using angularjs to get http get request. i want to display some information from the remote server.. its working absolutly fine from any http test server. but other links are not working.
Asked
Active
Viewed 555 times
-1
-
1This is a problem to address server side, typically when you call a server that is not on the same domain that your front application. If you're managing the server side too, then you have to set the right HTTP header on the server response (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS). – Boulzy Oct 17 '16 at 14:13
-
Thank you so much.. – itsMe Oct 17 '16 at 14:26
-
acutally i have tried almost every approch .. doesnt work... accoding to the documentation i have added the required code. but still its not working. same problem – itsMe Oct 17 '16 at 15:18
-
Possible duplicate of ["No 'Access-Control-Allow-Origin' header is present on the requested resource"](http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource) – Adam Michalik Oct 19 '16 at 13:59
-
Other posts answering this question: http://stackoverflow.com/q/24134117/466738 http://stackoverflow.com/q/29547003/466738 – Adam Michalik Oct 19 '16 at 14:00
1 Answers
1
The Spring Framework provides a CorsFilter you can use for filter-based frameworks like Spring Security. Add the following to one of your @Configuration
classes to configure it.
@Bean
public FilterRegistrationBean corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("http://localhost:3000");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/**", config);
FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
bean.setOrder(0);
return bean;
}
Where http://localhost:3000
is the client you want to allow.

Matt Raible
- 8,187
- 9
- 61
- 120