Answer the question
In order to leave comments, you need to log in
Why is Cyrillic data not transmitted via fetch during a POST request?
Customer:
let userName = 'Yana';
let text = "text";
fetch('/chat', {
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
'body': [text, userName],
'Content-Type': 'application/json'
},
method: 'POST',
})
router.post('/',function(req,res){
console.log('post!!!', req.headers.body);
res.status(200).send();
});
Answer the question
In order to leave comments, you need to log in
Correct the headers, two Content-Type with different quotes and types of transmitted data indicates that you copied it from somewhere, and besides, the body was stuffed there as an array.
Here is a piece of working code for a post request (and not only):
if (type.toLowerCase() === 'post') {
params = JSON.stringify(params);
}
const fetchOptions = {
method: type,
mode: REQUEST_API.mode,
headers: new Headers({
Accept: 'application/json',
'Content-Type': 'application/json'
}),
credentials: REQUEST_API.credentials,
body: params
};
return fetch(url, fetchOptions);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question