简体   繁体   English

无法使用fetch api发送DELETE请求

[英]Not able to send a DELETE request with fetch api

When I send a delete request to a certain endpoint, for example with httpie from terminal like 当我向某个端点发送删除请求时,例如使用来自终端的httpie

http delete http://localhost:8181/admin/applications/uspecs

I get a valid behavior, as in { success: true } as response body. 我得到了一个有效的行为,如{ success: true }作为响应主体。 But when I do 但是,当我这样做

fetch (
  'http://localhost:8181/admin/applications/uspecs',
  { method: 'DELETE' }
)
.then(res => doSomethingWithResponse())
.catch(err => console.error(err))

In javascript code, then I get a 在javascript代码中,然后我得到了一个

Fetch API cannot load http://localhost:8181/admin/applications/uspecs.
Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response.

error on the console. 控制台上的错误。 What am I missing? 我错过了什么? I am getting a valid methods list on options request. 我在选项请求上获得了有效的方法列表。

You need to send the Access-Control-Allow-Methods header containing the allowed methods. 您需要发送包含允许方法的Access-Control-Allow-Methods标头。 Currently your header is named methods . 目前您的标题名为methods

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM