【发布时间】:2020-01-28 06:45:56
【问题描述】:
我正在尝试在 Angular 中执行 PUT 方法,
app.component.ts:
this.http.put( this.updateurl+ this.userid, JSON.stringify(user.value))
.subscribe(response =>{
console.log(response);
});
当我这样做时,我收到如下错误:
Access to XMLHttpRequest at 'http:// ***********' from origin 'http://localhost:4200' has been
blocked by CORS policy: Method PUT is not allowed by Access-Control-Allow-Methods in preflight
response.
我该如何解决这个问题。
【问题讨论】:
-
您的服务器端技术是什么? cors 策略可以在服务器端添加,而不是在角度端。
-
您应该在服务器端启用 cors(跨源资源共享)。您可以为特定 url 和所有 url 启用它。
-
请阅读this
标签: javascript angular core