Ashok Kumar
Ashok Kumar

Reputation: 1

Angular 4, http post is giving giving error : XMLHttpRequest cannot load

I am developing an application on angular and I am new to it.

Here is my requirement, I am trying to get the data using http post. But it is giving below error. XMLHttpRequest cannot load http://162.12.0.117:8081/Server/config/getAllConfigurationValues. 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:4200' is therefore not allowed access.

Below is the my code.

    let headers = new Headers({ 'Content-Type': 'application/json'});

    let options = new RequestOptions({ headers: headers });
    this.http.post(
    "http://162.12.0.117:8081/Server/config/getAllConfigurationValues", 
    {
        "userName": "username",
        "password": "password"
    },
    options
    ).subscribe(
        (result) => function(){
            console.log(result);
        }
    );

Upvotes: 0

Views: 694

Answers (1)

Marko Nikolic
Marko Nikolic

Reputation: 31

Cross Origin Requests should be allowed on server side.

Upvotes: 1

Related Questions