【发布时间】:2019-03-15 18:05:18
【问题描述】:
我正在尝试发出 PUT 请求,但出现以下错误:
Failed to load <localhost:8080/uaa/groups/dfsfaes8323df32>: Response for preflight does not have HTTP ok status.
显然,当我发出 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);
}
);
【问题讨论】:
-
您需要配置
https://ice.<mydomain>.com服务器,使其允许/uaadev/Groups/{groupId}端点的PUT 请求。现在,403 服务器响应表明服务器不允许该 /uaadev/Groups/{groupId}` 端点的 PUT 请求。您无法在前端 JavaScript 中做任何事情来影响/改变它。 -
在此处标记@sideshowbarker - 是的,它与 Angular 或前端代码完全无关。您必须在后端配置 CORS 以在
Acces-Control-Allow-Methods标头中包含PUT或PATCH。您可能可以使用不透明的fetch,但同样取决于您的后端设置。 -
不透明的获取是通过设置
{mode:'no-cors'}来完成的吧?
标签: angular rest cors angular6 preflight