简体   繁体   English

使用axios作为客户端通过express.js中的Delete方法发送和获取参数

[英]Sending and getting parameters through Delete method in express.js using axios as client

Please I have written an API in express js for a DELETE request which checks for a password parameter before doing other things. 请我在Express js中为DELETE请求编写了一个API,该API在执行其他操作之前先检查密码参数。 This whole thing works locally on postman, but not with the hosted server on heroku. 这整个事情在邮递员本地工作,但不适用于heroku上的托管服务器。

Here is a snippet from the API 这是API的摘录

  ...
 if (!req.body.password) {
   return res.status(400).json({ message: "input password"})
  }
  ...

And on my Client side, I have 在我的客户端,

axios.delete('url/id', ({password: 'password'}))
 .then()
 .catch()

The Issue is this, req.body.password is not being noticed, it is seen as undefined on the hosted server 问题是这样,req.body.password未被注意,在托管服务器上被视为未定义

It's not common to pass something into delete body so it's different than post, put and patch requests as you can see here 将内容传递到删除正文中并不常见,因此与发布,放置和修补请求不同, 如您在此处看到的

You should do it like this: 您应该这样做:

axios.delete('/some/uri', { data: 'my delete body' })

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

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