Javascript Nest无法从提取请求中识别POST
我有一个react应用程序在端口3000上运行,向端口8080上的NestJS服务器发出POST请求。我的客户是:Javascript Nest无法从提取请求中识别POST,javascript,http,nestjs,Javascript,Http,Nestjs,我有一个react应用程序在端口3000上运行,向端口8080上的NestJS服务器发出POST请求。我的客户是: fetch('http://localhost:8080/confirm-reservation', { method: 'POST', headers: { 'Content-Type':'application/json' }, mode: 'cors', data: { key: 'this is
fetch('http://localhost:8080/confirm-reservation', {
method: 'POST',
headers: {
'Content-Type':'application/json'
},
mode: 'cors',
data: {
key: 'this is a value'
}
})
控制器是一个简单的控制系统
@Controller('confirm-reservation')
export class AppController {
@Post()
postForm(@Body() form:any) {
console.log(form)
}
}
在我的主服务器上,我有app.enableCors()代码>
当我提交请求时,我得到一个空的{}
我可以使用与浏览器标题相同的邮递员发出请求,并且可以在服务器中看到req对象,但不能使用fetch。这是为什么?使用选项对象中的body
属性,没有数据
属性。然后将数据作为JSON发送
fetch('http://localhost:8080/confirm-reservation', {
method: 'POST',
headers: {
'Content-Type':'application/json'
},
mode: 'cors',
body: JSON.stringify({
key: 'this is a value'
})
})
哦,天哪,真是一个错过。非常感谢。