problem description
do not know the description is clear, that is to say, the request after preflight is directly initiated by the browser, did not follow my front-end code?
=
Front and back end separate items
the front end initiates basic authentication across domains through the fetch
function, and the backend (spring security) authentication returns a response.
but the response
obtained in fetch
has no corresponding header information
the environmental background of the problems and what methods you have tried
the front and rear ends are separated. When making a cross-domain request, we refer to some cors instructions. When initiating a request, we will first initiate a
preflight pre-check of OPTIONs, and then pass the pre-check to perform the real request operation. However, in the observation, the respone obtained by fetch
does not have any header information. I do not know if the browser has blocked it (grab the package locally with wireshark, and there is no problem with the request response). For more information, please see the code. No, I don"t know if I have described it clearly. I"ve been writing middleware before, and I haven"t done a front-end combination project, so I have no concept at all
.
related codes
/ / Please paste the code text below (do not replace the code with pictures)
this is the result of grabbing the package:
@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowedOrigins(Arrays.asList("*"));
corsConfiguration.setAllowedMethods(Arrays.asList("GET","POST"));
corsConfiguration.setAllowedHeaders(Arrays.asList("*"));
UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**",corsConfiguration);
return urlBasedCorsConfigurationSource;
}
what result do you expect? What is the error message actually seen?
I want to get the response in the fetch function, get the token generated by spring from it and save it, but I can"t get it