【发布时间】:2021-05-25 17:39:25
【问题描述】:
我有一个 ReactJs 前端 (localhost),我从中调用 NestJs 后端:
fetch("http://myappherokuapp.com/user/login", {
method: "POST",
mode: 'no-cors',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'
},
body: encodedToken
})
.then(res => res.json())
.then(
(result) => {
console.log(result);
},
(error) => {
//TODO
}
);
这是 NestJs 后端控制器:
@Controller('user')
//init...
@Post('login')
async login(@Res() res, @Body() userLoginDto: UserLoginDto) {
return res.status(HttpStatus.OK).json({
logged: 'true'
});
}
在浏览器开发者控制台中,检查响应我“无法加载响应数据”,在 res.json() 的 res.json() 中我发现了这个:
如果我从 PostMan 调用 /login,我会收到正确的 200 响应:
{ “记录”:“真实” }
会不会是 cors 问题?关于内容类型?
你有什么想法吗?
谢谢
【问题讨论】:
标签: reactjs express nestjs httpresponse