gpt4 book ai didi

java - http url : 401 Unauthorized 的 HTTP 失败响应

转载 作者:行者123 更新时间:2023-12-02 08:59:34 33 4
gpt4 key购买 nike

每当我使用以下方法时,我都可以从 Angular 调用我的服务

   @Override
protected void configure(HttpSecurity http) throws Exception{
http.csrf().disable().authorizeRequests().antMatchers("/").permitAll();
}

但是当我如下更改配置方法时,我收到 401 错误。

@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf().disable()
// dont authenticate this particular request
.authorizeRequests().antMatchers("/authenticate", "/register","/basicauth").permitAll().
// all other requests need to be authenticated
anyRequest().authenticated().and().
// make sure we use stateless session; session won't be used to
// store user's state.
exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint).and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);

// Add a filter to validate the tokens with every request
httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
}

如何克服这个问题。

我的错误如下

enter image description here

最佳答案

您需要在 antMatchers() 中指定整个端点。据我所知,您尝试访问的网址是 .../api/v1/basicauth => 将 /basicauth 字符串更改为 /api/v1/basicauth

关于java - http url : 401 Unauthorized 的 HTTP 失败响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60261572/

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