我正在試圖向我的節點JS服務器發出接受post/put調用的請求。我嘗試通過chai發送後調用的參數在服務器(req.body.myparam)上不可見。
我曾嘗試用下面POST請求,但最終有沒有效果: -
通過Chai的發佈請求
var host = "http://localhost:3000";
var path = "/myPath";
chai.request(host).post(path).field('myparam' , 'test').end(function(error, response, body) {
和
chai.request(host).post(path).send({'myparam' : 'test'}).end(function(error, response, body) {
節點JS代碼如下: -
app.put ('/mypath', function(req, res){ //Handling post request to create league
createDoc (req, res);
})
app.post ('/mypath', function(req, res){ //Handling post request to create league
createDoc (req, res);
})
var createDoc = function (req, res) {
var myparam = req.body.myparam; //league id to create new league
if (!myparam) {
res.status(400).json({error : 'myparam is missing'});
return;
}
};
上面代碼中去到myparam丟失。
請讓我知道什麼是做同樣的最好的方式。
在此先感謝。
你可以分享端點的代碼嗎? –
更新了代碼。如果你需要其他東西,請告訴我。 –
我沒有看到在任何地方定義的「聯盟」? – Derek