How to Solve 403 Error in Spring Boot Post Request

前端 未结 3 810
醉酒成梦
醉酒成梦 2020-12-24 10:44

I am newbie in spring boot rest services. I have developed some rest api in spring boot using maven project.

I have successfully developed Get and <

3条回答
  •  旧时难觅i
    2020-12-24 11:17

    To build on the accepted answer

    Many HTTP client libraries (eg Axios) implicitly set a Content-Type: JSON header for POST requests. In my case, I forgot to allow that header causing only POSTS to fail.

    @Bean
    CorsConfigurationSource corsConfigurationSource() {
        ...
        configuration.addAllowedHeader("Content-Type"); // <- ALLOW THIS HEADER 
        ...
    }
    

提交回复
热议问题