简体   繁体   English

从源 'http://localhost:3000' 在 'http://localhost:8080/home/data' 访问 XMLHttpRequest

[英]Access to XMLHttpRequest at 'http://localhost:8080/home/data' from origin 'http://localhost:3000'

Well I have Backend which a Spring Boot Application with Security.好吧,我有一个带有安全性的 Spring 引导应用程序的后端。 This is how the Security Configuration looks like:这是安全配置的样子:

 @Override
protected void configure(HttpSecurity http) throws Exception {

    http.cors()
            .and()
            .authorizeRequests()
            .antMatchers("/home/**")
            .authenticated()
            .and()
            .formLogin()
    .defaultSuccessUrl("/home")
            .and()
            .logout()
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
            .logoutSuccessUrl("/login")
            .invalidateHttpSession(true)        // set invalidation state when logout
            .deleteCookies("JSESSIONID");

For frontend I have a React.js application.对于前端,我有一个 React.js 应用程序。 If you press on a button at this application a GET request to this url should be executed: 'http://localhost:8080/home/hives如果您在此应用程序上按下按钮,则应执行对此 url 的 GET 请求: 'http://localhost:8080/home/hives

This is my code in React.js getDataAxios(){这是我在 React.js 中的代码 getDataAxios(){

     axios.get('http://localhost:8080/home/data', {
        mode: "no-cors",
        auth: {
            username: 'user.user@provider.io',
            password: 'password'
          }
      })
      .then(function (response) {
        console.log(response);
      })
}

The problem is that I am getting this exception on the browser console when pressing the button where this function is executed:问题是,当按下执行此 function 的按钮时,我在浏览器控制台上收到此异常:

Access to XMLHttpRequest at 'http://localhost:8080/home/data' from origin 'http://localhost:3000' 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.

Well I have Backend which a Spring Boot Application with Security.好吧,我有一个带有安全性的 Spring 引导应用程序的后端。 This is how the Security Configuration looks like:这是安全配置的样子:

 @Override
protected void configure(HttpSecurity http) throws Exception {

    http.cors()
            .and()
            .authorizeRequests()
            .antMatchers("/home/**")
            .authenticated()
            .and()
            .formLogin()
    .defaultSuccessUrl("/home")
            .and()
            .logout()
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
            .logoutSuccessUrl("/login")
            .invalidateHttpSession(true)        // set invalidation state when logout
            .deleteCookies("JSESSIONID");

For frontend I have a React.js application.对于前端,我有一个 React.js 应用程序。 If you press on a button at this application a GET request to this url should be executed: 'http://localhost:8080/home/hives如果您在此应用程序上按下按钮,则应执行对此 url 的 GET 请求: 'http://localhost:8080/home/hives

This is my code in React.js getDataAxios(){这是我在 React.js 中的代码 getDataAxios(){

     axios.get('http://localhost:8080/home/data', {
        mode: "no-cors",
        auth: {
            username: 'user.user@provider.io',
            password: 'password'
          }
      })
      .then(function (response) {
        console.log(response);
      })
}

The problem is that I am getting this exception on the browser console when pressing the button where this function is executed:问题是,当按下执行此 function 的按钮时,我在浏览器控制台上收到此异常:

Access to XMLHttpRequest at 'http://localhost:8080/home/data' from origin 'http://localhost:3000' 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.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 XMLHttpRequest无法加载“此URL”来源Access:Control-Allow-Origin不允许使用原始http:// localhost:3000。 - XMLHttpRequest cannot load “THIS URL” Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin. Access-Control-Allow-Origin不允许来源http:// localhost:8080 - Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin XMLHttpRequest无法加载请求的资源上不存在“Access-Control-Allow-Origin”标头。 Origin'http:// localhost:3000'Google maps - XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' Google maps 因此,不允许来源'http:// localhost:3000'访问Twitter API - Origin 'http://localhost:3000' is therefore not allowed access Twitter API XMLHttpRequest无法加载http:// localhost:3000 / get - XMLHttpRequest cannot load http://localhost:3000/get CORS 策略已阻止访问从源“http://localhost:3000”获取 - Access to fetch at from origin 'http://localhost:3000' has been blocked by CORS policy CORS 策略已阻止从源“http://localhost:3000”访问“https://localhost:7144/api/employees” - Access to fetch at 'https://localhost:7144/api/employees' from origin 'http://localhost:3000' has been blocked by CORS policy ReactJs 中的 CORS 政策阻止了从来源“http://localhost:3000”访问“http://example.com/myApi” - Access to fetch at 'http://example.com/myApi' from origin 'http://localhost:3000' has been blocked by CORS policy in ReactJs 无法加载资源:Access-Control-Allow-Origin不允许使用原始http:// localhost:8080 - Failed to load resource: Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin不允许AngularJS Origin http:// localhost:8080 - AngularJS Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM