Error SEC7120: [CORS] The origin 'http://localhost:4200' did not find 'http://localhost:4200' in the Access-Control-Allow-Origin response

不羁岁月 提交于 2019-12-11 20:55:16

问题


Actually I am trying to connect an Angular app with my Maven-Jersey-webapp(implements Rest Services concept) and getting this error.

More Details: I am using Oracle10g XE Database Eclipse IDE for maven Project(http://localhost:8080/MavenProject) Angular CLI(http://localhost:4200/)

I want to retrieve data from database(Stored in students table) and then display that data in Angular App in a Table my jersey project returns the table data in JSON and XML format(Running Successfully)

retrieving student table data in JSON format using Maven-jersey-webapp implementing rest

angular code making get request using HttpClient

error which i get while making get request


回答1:


You can fix this by checking if you are using

http vs https

Just use http to fix it. After that, Add that in the header in the angular service you created like doing a code like this

 const httpOptions = {
            headers: new HttpHeaders({
                'Access-Control-Allow-Origin': 'http://localhost:4200', // -->Add this line
                'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS',
                'Access-Control-Allow-Headers': '*',
                'Content-Type': 'application/json',
                'Accept': 'application/json'
            })
        };

Just check the string value you passed in your code. Sometimes your eye gets trick on these values. Like

http://localhost:4200 vs https://localhost:4200



来源:https://stackoverflow.com/questions/50714097/error-sec7120-cors-the-origin-http-localhost4200-did-not-find-http-lo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!