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);
       }
Metin Bulak
  • 537
  • 4
  • 8
  • 30
  • 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. – Niladri Jan 25 '19 at 20:37
  • 1
    There is also a section about this in the Angular docs here: https://angular.io/guide/deployment#requesting-services-from-a-different-server-cors – DeborahK Jan 25 '19 at 23:45
  • which back end technology are you using ?? – Jenson Raby Jan 28 '19 at 07:42

0 Answers0