[英]POST request containing ascii characters [x-www-form-urlencoded]
[英]Postman x-www-form-urlencoded returns null value for a POST request even though the input field is filled
我使用了郵遞員的原始選項,並且可以正常工作,我的輸入值按預期返回。 但是,當我使用x-form-urlencoded選項時,將返回“ null”。 獲取請求都很好。 在郵遞員橫截面的屏幕截圖下方找到:
我使用以下postgres腳本手動創建了表和行:
CREATE TABLE graduates (id SERIAL PRIMARY KEY, name TEXT);
CREATE TABLE offers (id SERIAL PRIMARY KEY, title TEXT, graduate_id INTEGER REFERENCES graduates (id) ON DELETE CASCADE);
INSERT INTO graduates (name) VALUES ('Elie'), ('Michael'), ('Matt'), ('Joel');
INSERT INTO offers (title, graduate_id) VALUES ('Teacher', 1), ('Super Teacher', 2), ('Mathematician', 3), ('Developer', 4), ('Super Doctor 1', 3), ('Super Doctor 2', 4), ('Super Developer 1', 2);
我的畢業生申請POST路線的摘要如下:
// This route is mounted on /graduates in app.js
router.post("/", async (req, res, next) => {
try {
const result = await db.query(
"INSERT INTO graduates (name) VALUES ($1) RETURNING *",
[req.body.name]
);
return res.status(201).send(result.rows[0]);
} catch(err) {
return next(err);
}
});
我期待一個答案。 謝謝。
您需要一個解析器才能從請求正文中獲取名稱。 現在有一個未構建的Express。 在頂部添加這兩行,它將起作用:
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.