My goal is to debug why I can send HTTP GET request without RequestHeaders
, but I can't send HTTP GET request with RequestHeaders
, on browser.
I am following the spring.io's tutorial to learn more about CSRF and CORS.
What I've tried:
- Send GET Request to
http://localhost:8080/user
with Request HeaderAuthorization: Basic .....
would return me CORS error
Access to XMLHttpRequest at 'http://localhost:8080/user' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
- SEND GET Request to
http://localhost:8080/user
without a Request Header will not return me an CORS error.
Note: I've double check that CORS issue is resolved for any GET request if I did not add Request Header.
@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Collections.singletonList("http://localhost:4200"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST"));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
However, it does not fix CORS issue if I send the GET /user
with a Request Header Authorization: Basic ....
My expected result is: When I send a GET request with a Request Header, it should not return a CORS error.
My actual result is: It return a CORS error.