预检响应没有 HTTP ok 状态。Angular 6 中的 403

Dav*_*alu 1 rest cors preflight angular angular6

我正在尝试发出 PUT 请求,但出现以下错误:

Failed to load <localhost:8080/uaa/groups/dfsfaes8323df32>: Response for preflight does not have HTTP ok status.
Run Code Online (Sandbox Code Playgroud)

显然,当我发出 GET 和 POST 请求并在邮递员中工作时它有效,但它不适用于我的代码中的 PUT 请求。

这是我的要求:

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);
  }
);
Run Code Online (Sandbox Code Playgroud)

ric*_*azo 5

这是因为您必须确保您的服务器配置为在 PUT 请求之前为浏览器触发的OPTIONS请求发送 200 或 204 。

这里看到第一个回复

你用 PUT 得到这个的原因是因为它触发了 OPTIONS(浏览器的一个额外的预检请求)来查看更多关于什么方法触发这个你可以在这里查看。基本上,浏览器在 PUT 之前“ping”服务器。

令人沮丧的是,这似乎是一个前端问题,因为 PUT 请求在测试时有效(即如果您使用邮递员),但在浏览器中无效。

所以这不是前端问题,无法使用 Angular 解决。