我有一個在端口 3000 上運行的 React 應用程序,向端口 8080 上的 NestJS 服務器發出 POST 請求。我的客戶端是: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();當我提交請求時,我得到一個空的{}我可以使用具有與瀏覽器相同標頭的 Postman 發出請求,并且能夠在服務器中看到 req 對象,但不能通過使用 fetch 來查看。為什么是這樣?
Nest 無法識別來自 fetch 請求的 POST
慕少森
2023-07-29 16:41:59