body is empty when parsing DELETE request with express and body-parser

后端 未结 1 1284
时光说笑
时光说笑 2020-12-20 14:56

I\'m using expressjs and the body-parser middleware.

This is how I initiate it:

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParse         


        
相关标签:
1条回答
  • 2020-12-20 15:31

    The $http service source code, a DELETE request using $http does not allow for data to be sent in the body of the request.

    The spec for a DELETE request is somewhat vague on whether or not a request body should be allowed, but Angular does not support it.

    The only methods that allow for request bodies are POST, PUT, and PATCH. So the problem is not anywhere in your code, its in Angular's $http service.

    Use this

    $httpProvider.defaults.headers.delete = { "Content-Type": "application/json;charset=utf-8" };
    

    and then

    $http.delete(url, { data: data })

    0 讨论(0)
提交回复
热议问题