[英]How can I get the raw HTTP message body using the request library in Node.js?
[英]I can not get request in body format in Node.js
我在服務器上接收正文格式的請求時遇到問題。
我使用的是Express 版本 4.17.1。 文檔表明我不必使用 body-parserer,但我可以直接使用 express 功能“express.json ()”來完成
但是,我一直試圖讓它工作很長時間,但沒有任何反應:控制台沒有顯示任何內容。 它似乎根本無法識別該請求。
我正在以正文格式 JSON 完成來自 Postman 的所有請求。
這是我的代碼:
const express = require("express");
const formidable = require("express-formidable");
const cors = require("cors");
const dotenv = require("dotenv").config();
const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(formidable());
app.use(cors());
(...)
app.post("/list", async (req, res) => {
try {
console.log(req.body);
} catch (error) {
return res.status(400).json({ message: error.message });
}
});
我究竟做錯了什么?
非常感謝您的時間和提前幫助。
根據Content-Type
header 中定義的類型快速解析請求體。 嘗試使用 header Content-Type: application/json
進行請求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.