我正在试图向我的节点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