I need to convert the following request, which is the following code for react-native:
Nodejs:
const request = require('request');
var areaRiservata = {
url: "https://www.iliad.it/account/",
method: "POST",
followAllRedirects: true,
jar: true,
form: {
"login-ident": config.iliad.username,
"login-pwd": config.iliad.password
}
}
exports.Login = function(callback) {
request.post(areaRiservata, function (err,res,body) {
if (String(body).match(/ID utente o password non corretto./g) != null) {
//Login fallito, restituisco errore
callback('Errore durante il login. ID utente o password non corretto.');
} else {
//Login effettuato, restituisco il sorgente della pagina
callback(body.replace(/<\/span> \//g, ' /').replace(/GB<br>/g, 'GB</span>'));
}
});
};
I have tried this, but it seems to not work.
React-native
fetch('https://www.iliad.it/account/', {
method: 'POST',
header: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: JSON.stringify({
'login-ident': ident,
'login-pwd': pwd,
}),
})
.then(response => response.text())
For example the fetch does not contain these fields, as I can do.
followAllRedirects: true,
jar: true,
Where am I doing wrong?