当我尝试在Angular 7 Web应用程序中进行PATCH请求时,遇到了问题。 我的后端代码如下:
app.use((req, res, next) => {
res.set({
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "'Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token'",
});
next();
});
在我的前端服务中,我有以下内容:
patchEntity(ent: any, id) {
let headers = new Headers({ 'Content-Type': '*' });
let options = new RequestOptions({ headers: headers });
return this.http.patch('my_url', ent).map((res: Response) => res.json());
};
错误信息为:
Access to XMLHttpRequest at 'my_url' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
我能帮你做什么呢?谢谢。
Access-Control-Allow-Methods
的通配符在所有浏览器中尚未得到支持。此外,错误消息表明它返回了非200状态,因此您应该先查看为什么出错。 - user184994POST、GET、OPTIONS、PATCH
以及其他您关心的值。 - user184994