I have been going through this the whole afternoon, please help me debug.
Client Side:
fetch('/admin/edit/tags', {
method: 'post',
credentials: 'same-origin',
headers: {
'content-type': 'application/json',
'accept': 'application/json'
},
body: form.getFormData('json')
})...
console.log(form.getFormData('json'));
returns {"id":"11","tag":"tag12","submit":"Update"}
Server Side (Node.js):
Code for request handling:
function (req, res) {
var bufferBody = [];
req.on('error', err => {
return res.status(400).send('request error.');
}).on('data', chunk => {
bufferBody.push(chunk);
}).on('end', () => {
res.on('error', err => {
return res.status(400).send('response error.');
});
req.bufferBody = bufferBody;
req.stringBody = Buffer.concat(bufferBody).toString();
//req.json = JSON.parse(req.stringBody);
req.body = qs.parse(req.stringBody);
})
}
The Route:
{
method: 'POST',
path: '/admin/edit/tags',
handle: PC(function*(req, res) {
var data = req.body;
console.log(data);
console.log(req.stringBody);
})
}
This is the buffer string: theBuffer.toString()
%7B%22id%22%3A%2211%22%2C%22tag%22%3A%22tag12%22%2C%22submit%22%3A%22Update%22%7D=
This is the query string: qs.parse(theBufferString)
{ '{"id":"11","tag":"tag12","submit":"Update"}': '' }
I have checked every where, headers are correct. What could be the cause that could turn jsonString to queryString?
I know that I can turn jsObject to queryString, but I really really want to use jsonString.