Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
417 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...