I have the following code running on NodeJS
/*jshint esversion: 6 */
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 8080;
app.use(bodyParser.urlencoded({extended: false}));
app.post("/home", (req, res)=>{
res.set("Content-Type", "text/plain");
res.set("Accept-Charset", "utf-8");
const msg = req.body.phrase;
console.log("RECEIVED: "+msg);
res.send("frase : "+msg);
});
app.listen(port, (err)=>{
if (err){
throw err;
}
console.log("Server started on http://localhost:"+port);
});
When I make a request via post containing the characters +
and &
, these characters are replaced or the result returns wrong, example of the request:
fetch("http://localhost:8080/home", {
method: 'POST',
headers: {'Content-Type':'application/x-www-form-urlencoded'},
body: 'phrase=eu+ela&voce'
}).then(function(response){
return response.text();
}).then(function(text){
console.log(text);
});
eu+voce&ela
returns
eu voce