程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了带有角数字格式Cors错误的Spring RequestParam大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决带有角数字格式Cors错误的Spring requestParam?

开发过程中遇到带有角数字格式Cors错误的Spring requestParam的问题如何解决?下面主要结合日常开发的经验,给出你关于带有角数字格式Cors错误的Spring requestParam的解决方法建议,希望对你解决带有角数字格式Cors错误的Spring requestParam有所启发或帮助;

所以我试图用 2 个参数作为数字向这个端点发出一个发布请求......我正确地获得了参数......发布时我得到 从源 'http://localhost:4200' 访问 XMLhttprequest at 'http://localhost:8080/API/user/addCartItem' 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。 错误 ... 当我从邮递员那里应用相同的方法时,everythink 就可以正常运行。

    @PreAuthorize("hasAnyRole('RolE_admin','RolE_USER')")
    @requestMapPing(value = "/addCartItem/{CartID}{productID}",method = requestMethod.POST )
    public List<CartItem> addCartItem(@requestParam Long cartID,@requestParam Long productID) {
        return cartservice.addCartItem(cartID,productID);
    }
  addCartItem(cartID:number,productID:number):Observable<any>{
    const httpParams = new httpParams({
      fromObject:{
        cartID,productID,}
    })
    return this.httpClIEnt.post('http://localhost:8080/API/user/addCartItem',{ httpParams })
  }

这是安全配置类

@EnableWebMvc
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(
  prePostEnabled = truE)
public class SecutiryConfig extends WebSecurityConfigurerAdapter {
    @autowired
    UserDetailsserviceImpl userDetailsservice;
    @autowired 
    private AuthEntryPointJwt unauthorizedHandler;
    @Bean
    public AuthTokenFilter authenticationJwtTokenFilter() {
        return new AuthTokenFilter();
    }
    @OverrIDe
    public voID configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
        authenticationManagerBuilder.userDetailsservice(userDetailsservicE).passwordEncoder(passwordEncoder());
    }
    @Bean 
    @OverrIDe
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }
    @Bean
    public passwordEncoder passwordEncoder() {
        return new BCryptpasswordEncoder();
    }
    @OverrIDe
    protected voID configure(httpSecurity http) throws Exception {
        http.cors().and().csrf().disable()
            .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
            .authorizerequests().antMatchers("/API/auth/**").permitAll()
            .antMatchers("/API/admin/**").permitAll()
            .antMatchers("/API/user/**").permitAll()
            .antMatchers("/API/public/**").permitAll()
            .anyrequest().authenticated();
        http.addFilterBefore(authenticationJwtTokenFilter(),UsernamepasswordAuthenticationFilter.class);
    }
    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @OverrIDe
            public voID addCorsmapPings(CorsRegistry registry) {
                 registry.addMapPing("/**") 
                 .allowedMethods("GET","POST","PUT","deletE")
                 .allowedheaders("*")
                 .allowedOrigins("*");
            }
        };
    }
}

带有角数字格式Cors错误的Spring RequestParam

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的带有角数字格式Cors错误的Spring RequestParam全部内容,希望文章能够帮你解决带有角数字格式Cors错误的Spring RequestParam所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。