Responded with a status of 401

I am getting this error when calling and I have to clue how to fix it

postData () {

   
    var headers = new HttpHeaders();
    headers = headers.set('Authorization','xxxxxxxxxxxxx');
    headers = headers.set('Content-Type','application/xxxxxxxxxx');
    headers = headers.set("Access-Control-Allow-Origin", "http://localhost:");
    headers = headers.set("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
    headers = headers.set("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Authorization, Origin, Accept");


    // let requestOptions = {
    //   headers: new HttpHeaders()
    //  };
    // requestOptions.headers = headers;

    let body = {
      grant_type:'password',
      username:'user',
      password:'user'
    };

    console.log(qs.stringify(body))
    console.log(headers)

    this.http.post(apiUrl,qs.stringify(body), {headers : headers} )
    .subscribe(data=>{
      console.log(data.toString)
    });
    
    }

Well I think you have to take a look at the server side.

The Server don’t let you on the requested url.

So the authorization goes wrong or the routing to the url is wrong.

Now you know where to look.

The headers will have to be configured on the server. You will need to make sure OPTIONS is also included with the other verbs.