I want to send a x-www-form-urlencoded request for the server. I give a json value for it like {username: 'asd', password: '12345'}.
Angular:
...
let headers: HttpHeaders = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded');
this._http.post('/api/authentication', form.value, {headers: headers, observe: 'response'}).subscribe((response:HttpResponse<Object>) => {
console.log(response); // response body {'{"username":"asd","password":"12345"}' : ""}
});
...
So I get something strange from back-end and I don't really understand what to change in my implementation to make this work like the input he got.
Nodejs (express):
//server.js
...
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true}));
...
--
//api/.../authentication.js
...
router.post('/', (req, res) => {
let post = req.body;
console.log( req.body); //same strange hash: {'{"username":"asd","password":"12345"}' : ""}
res.status(201).json(req.body);
});
...