No puedo obtener el cuerpo correcto en el servidor. Si uso el tipo de contenido de json, obtengo un cuerpo vacío, si uso urlencoded, obtengo el cuerpo pero no lo analizo. Se parece a esto { { "title": "New Title" }: '' } Esperaría acceder a una propiedad en el cuerpo así, req.body.title. Estoy usando la última versión de node y express.
Cliente
function editMovies() { //var putMethod = { method: 'PUT', headers: { "Content-Type": "content-type: application/json" } }; var putMethod = { method: 'PUT', headers: { "Content-Type": "application/x-www-form-urlencoded" } }; putMethod.body = JSON.stringify({ "title": "New Title" }); fetch("/api/movies/2", putMethod).then(function (response) {}); }Servidor
app.use(express.json()); app.use(express.urlencoded({ extended: true })); app.put('/api/movies/:id', function (req, res) { var id = req.params.id; console.log('put called with:' + req.body.title); });