2
votes

I try to configure OpenFeign on my spring boot application, i use pokeapi to test.

i make this code:

@FeignClient(value = "pokeapi", url = "https://pokeapi.co")
public interface PokeApiClient {

@Headers("Content-Type: application/json")
@RequestMapping(method = RequestMethod.GET, value = "/api/v2/pokemon/{name}", consumes = 
"application/json")
Optional<Pokemon> findPokemonByName(@PathVariable("name") String name);

}

But when i make this call this error happens: feign.FeignException$Forbidden: [403 Forbidden] during [GET] to [https://pokeapi.co/api/v2/pokemon/ditto] [PokeApiClient#findPokemonByName(String)]: [error code: 1010]

What should i do in this case?

I tried to configure the WebSecurity with this:

@Configuration
@EnableWebSecurity
public class HttpConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeRequests()
                .antMatchers(HttpMethod.POST, "/**/authenticate").permitAll()
                .antMatchers(HttpMethod.GET, "/**/get-public-key").permitAll()
                .antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
                .anyRequest().permitAll();
    }
}
2

2 Answers

1
votes

A 403 forbidden means that the server understood the request but refuses authorization so that could be a permissions issue.. Error code 1010 is sometimes a blocked request by a website owner based upon your browser... hopefully these thoughts will be helpful? :)

0
votes

after long time able to resolved the issue by adding below RequestHeader "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"

After that it worked fine.

I am calling POST API using Feign Client and below is the scrrentshot enter image description here