gpt4 book ai didi

javascript - Angular 2 : Delete method not allowed

转载 作者:行者123 更新时间:2023-12-03 03:14:28 24 4
gpt4 key购买 nike

我的 Angular 2 http.delete 方法有问题。我的代码如下:

const headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded'});

this.http.delete(ConstVarService.url + 'api/tasks/UsunZapis', new RequestOptions({
headers: headers,
body: {tasksId: entryId}
})).subscribe((data) => {
console.log(data)
});

当我执行时,出现以下错误:

OPTIONS http://192.168.13.36/pplus-dev/appapi/api/tasks/UsunZapis 405 (Method Not Allowed)
Failed to load http://192.168.13.36/pplus-dev/appapi/api/tasks/UsunZapis: Response for preflight has invalid HTTP status code 405

但是在 Postman 中一切正常,相同的 URL、内容类型等。

最佳答案

为了发出跨域请求,浏览器会执行所谓的 pre-flight check 。您需要返回适当的 CORS header 才能允许浏览器发出请求。

关于javascript - Angular 2 : Delete method not allowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46827959/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com