has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.


前端顯示:

has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

  跨域問題,解決辦法:

      在對應的Controller上加上@CrossOrigin注解,或者在springBoot里面寫一個配置類實現全局跨域:

@SpringBootConfiguration
public class MyWebConfigurer implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry corsRegistry){
        /**
         * 所有請求都允許跨域,使用這種配置就不需要
         * 在interceptor中配置header了
         */
        corsRegistry.addMapping("/**")
                .allowCredentials(true)
                .allowedOrigins("http://localhost:8080")
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
                .allowedHeaders("*")
                .maxAge(3600);
    }

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource 接口在dev環境報跨域問題(has been blocked by CORS policy:Response to preflight request doesn't pass access control check:No 'Access-Control-Allow-Origin' header ispresent on the requested resource.),qa環境正常 Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed a 跨域請求錯誤: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource Access to XMLHttpRequest at '*url*' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. GET *url* net::ERR_FAILED Access to XMLHttpRequest at 'http://localhost:8090/user/getotp' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. [Nginx] 解決跨域been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. 跨域詳解 been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource 跨域詳解 been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource 前端出現has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM