问题
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