6

I have seperately restfull webservice. I use angular 6 in my front-end project. When I post data using httpClient I get an error like this

    error => cors header 'access-control-allow-origin' missing

here is my Angular code:

     login(username:string , password:string){
        var param = "username=" +username + "&password=" + password ;
        return this.http.post("http://localhost:8080/login",param);
       }
3
  • 4
    You need to set it up in both api and UI. I am not sure which framework you are using for your REST api. But there is a process to allow cross origin requests in each framework. Then you need to add the below header in your POST api call . let headers = new HttpHeaders().set('access-control-allow-origin',"http://localhost:8080/"); and pass that header to the http POST call. Commented Jan 25, 2019 at 20:37
  • 1
    There is also a section about this in the Angular docs here: angular.io/guide/… Commented Jan 25, 2019 at 23:45
  • which back end technology are you using ?? Commented Jan 28, 2019 at 7:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.