When making a DELETE request, it throws an error:

OPTIONS http: // localhost: 30117 / api / Goods 405 (Method Not Allowed)

Fetch API cannot load http: // localhost: 30117 / api / Goods . It doesn’t give access to the requested resource. Origin ' http: // localhost: 8070 ' is therefore not allowed access. The response had HTTP status code 405.

Error: TypeError: Failed to fetch

CORS is enabled on the Web Api server. On the client, I use the request module to send a request :

function _delete(tableName, id) { return new Promise(function(resolve, reject) { request({ method: "DELETE", url: `${_serverAddress}/${tableName}`, headers: { "Accept": "application/json" } }, function(error, response, body) { if (error) { reject(error); } else { resolve(body); } }) }); } 

GET requests work fine.

  • The error turned out to be quite simple: url: ${_serverAddress}/${tableName} , forgot to specify the id parameter here - user190794

1 answer 1

It is necessary to process on the server the OPTIONS request and set the corresponding Access-Cobtrol-Allow-Origin .