Sto provando a fare una richiesta al mio server JS nodo che accetta la chiamata post/put. I parametri che sto tentando di inviare con post call tramite chai non sono visibili sul server (req.body.myparam).
ho provato con richiesta post qui sotto, ma si è conclusa con risultati non: -
Richiesta messaggio via Chai
var host = "http://localhost:3000";
var path = "/myPath";
chai.request(host).post(path).field('myparam' , 'test').end(function(error, response, body) {
e
chai.request(host).post(path).send({'myparam' : 'test'}).end(function(error, response, body) {
codice
Nodo JS è il seguente: -
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;
}
};
Sopra codice va al myparam manca.
Per favore fatemi sapere qual è il modo migliore per fare lo stesso.
Grazie in anticipo.
È possibile condividere il codice dell'endpoint? –
Aggiornamento del codice. Per favore fatemi sapere se avete bisogno di qualsiasi altra cosa. –
Non vedo 'league' definito da nessuna parte? – Derek