Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

320
Views
¿Cómo publicar la solicitud?

¿Por qué el código genera un req.body vacío?

 const express = require("express"); const app = express(); app.use(express.urlencoded()); app.get("/", (req, res, next) => { res.send(`<script> fetch("/push", { body: "someText", headers: { "Content-Type": "text/html; charset=UTF-8", }, method: "POST", }).then((data) => console.log(data)); </script>`); }); app.post("/push", function (req, res, next) { console.log(req.body); //empty here //{} res.send(req.body); }); app.listen(3000);
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Su declaración de fetch realiza una solicitud POST con Content-Type: text/html , lo cual es muy inusual. express.urlencoded() no llena req.body para este tipo de contenido, solo está diseñado para Content-Type: application/x-www-form-urlencoded .

Puede analizar contenido textual arbitrario con código como este:

 var body = ""; req.on('data', function(chunk) { body += chunk.toString(); }) .on('end', function() { res.send(body); });
over 4 years ago · Santiago Trujillo Report

0

Simplemente agregue express.urlencoded({ extended: true }) también use express.js

 const express = require("express"); const app = express(); app.use(express.urlencoded({ extended: true })); app.use(express.json()) app.get("/", (req, res, next) => { res.send(`<script> fetch("/push", { body: "someText", headers: { "Content-Type": "text/html; charset=UTF-8", }, method: "POST", }).then((data) => console.log(data)); </script>`); }); app.post("/push", function (req, res, next) { console.log(req.body); res.send(req.body); }); app.listen(3000);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!