Sample 'Advanced REST Client' Requestreq.body未顯示爲鍵值對的一個,但req.headers和其他人做我使用郵差和高級REST客戶端創建下面的代碼基本POST請求
-
'use strict';
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var http = require('http');
// configure the app to use bodyParser()
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(bodyParser.json());
//app.listen(6666);
http.createServer(function (req, res) {
h2s(req, res);
}).listen(6666, '127.0.0.1');
console.log('Server running at http://127.0.0.1:6666/');
module.exports = function h2s(req, res) {
console.log("inside h2s");
app.use(function (req, res) {
console.log("req.body : " + req.body);
res.send("OK");
});
}
但是,當我調試時,我發現req.body在「req對象樹」中缺少。更奇怪的是,我對req.headers所做的所有更改都可以在req對象樹中找到。
看起來我似乎在犯一個微不足道的錯誤,但我無法弄清楚。經過一個小時左右的解決方案,但沒有運氣!
有沒有人可以弄清楚爲什麼req.body似乎從req對象樹中缺少?
對我有很大的幫助。謝謝!
的內容是什麼類型的申請,並就共同頭的細節。 –
感謝您的回覆,Manish。我附上了一張我在ARC發佈的請求的照片。 Content-Type是application/json。 – Sandy
你可以添加代碼來執行你試圖解析的任何數據嗎? – CruelEngine