Search code examples
angularrestcorsangular6preflight

Response for preflight does not have HTTP ok status. 403 in Angular 6


I am trying to make a PUT request but I get the following error:

Failed to load <localhost:8080/uaa/groups/dfsfaes8323df32>: Response for preflight does not have HTTP ok status.

Apparently it works when I make GET and POST requests and works in postman but it doesn't work with the PUT request within my code.

Here is my request:

let link = "https://ice.<mydomain>.com/uaadev/Groups/{groupId}";
link = link.replace("{groupId}", data);
const updLoad = {
  displayName: this.groupInfoObjects.displayName,
  description: this.groupInfoObjects.description,
  zoneId : "uaa",
  schemas: [
 "urn:scim:schemas:core:1.0"
  ]
};
let Header = new Headers({
  Authorization: `Bearer {token}`.replace("{token}", this.token),
  "Content-Type": "application/json",
  Accept: "application/json",
  "if-Match":"*"
});
let Option = new RequestOptions({ headers: Header });

this.http.put(link, updLoad, Option).subscribe(
  res => {
    console.log(res);
    console.log(res.status);
    if (res.status === 200) {
 this.fetchGroupInfo(this.dataservice.getDTO("GroupId"));
      swal(" Updated Successfully");
    }
  },
  error => {
    console.log("errroroorororororor");
    console.log("error object " +error);
  }
);

Solution

  • the process for solving these process is listed below:
    
    1.create a proxy.conf.json file 
    2.set it up like this:copy and paste the below code
    {
      "/dev/*": {
        "target": "https://google.com/",
        "secure": false
      },
      "changeOrigin": false,
      "logLevel": "debug"
    }
    
    3. add this to your package.json :
    "start": "ng serve --proxy-config ../Activated/proxy.conf.json",
    Note:Activated is the folder name that contains the angular code.
    4.you place your url link:
    let link = "dev/Groups/{groupId}" (just a sample)`enter code here`
    
    5.npm start to restart you application.