我不断获取数据:在我的 axios 调用中通过 nodemon 快速调用我的路由时未定义。
axios({
method: "POST",
url:"http://localhost:8080/oracle2/search",
headers: {"Content-Type" : "application/json;charset=utf-8"},
data: {customer_number: values.custNumber.toString(), last_name: values.last_name}
})
.then(console.log('Axios Callback'))
}
这是我的路线 oracle2:
router.post('/search', (req, res)=> {
router.use(cors());
router.use(bodyParser.json({ type: 'application/json' }))
router.use(bodyParser.urlencoded({ extended: false, type: 'application/json' }))
console.log(`The data: ${req.body}`)
res.sendStatus(200)
})
邮递员长这样:
标题:
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost:3000/
Content-Type: application/json;charset=utf-8
Content-Length: 51
Origin: http://localhost:3000
身体看起来像这样:
{"customer_number":"120231546","last_name":"Smith"}
任何帮助,将不胜感激。使用 Formik 值作为输入响应前端