gpt4 book ai didi

java - 预检响应没有 HTTP 正常状态。

转载 作者:行者123 更新时间:2023-11-30 05:56:38 24 4
gpt4 key购买 nike

我使用 Angular 6 登录的用户服务是:

loginUser(user:any):Observable<any>{
const headers=new HttpHeaders({'Access-Control-Allow-Origin':'*'});
return this.http.post("http://localhost:8080/login",user,{headers:headers});
}

saveUser(user:any):Observable<any>{
const headers=new HttpHeaders({'Access-Control-Allow-Origin':'*'});
return this.http.post("http://localhost:8080/registration",user,{headers:headers});
}

我在 Spring Boot 中将所有选项启用为 PermitAll :

@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf().disable().exceptionHandling().authenticationEntryPoint(authenticationEntryPoint).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests().
antMatchers("/**").permitAll()

.antMatchers("/registration").permitAll()
.antMatchers("/login").permitAll()
.antMatchers(HttpMethod.OPTIONS,"/**").permitAll()
.anyRequest().authenticated().and()
.formLogin()
.and()
.httpBasic();;

httpSecurity.addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class)
.addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class);

httpSecurity.headers().cacheControl();
httpSecurity.headers().httpStrictTransportSecurity().includeSubDomains(true).maxAgeInSeconds(31536000);

}

当我尝试从设置这些项目的计算机登录并注册时但是当我使用我的 IP 地址(例如 192.168.1.111:8080/login)从其他计算机访问本地主机时,它向我显示了第一个错误,例如:

Failed to load http://localhost:8080/login: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.1.111:8090' is therefore not allowed access.

然后我在 Chrome 中添加了允许的跨源扩展,它再次向我显示了如下错误:

Response for preflight does not have HTTP ok status.

最佳答案

httpSecurity.authorizeRequests().requestMatchers(CorsUtils::isPreFlightRequest).permitAll()

关于java - 预检响应没有 HTTP 正常状态。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53061773/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com