javascript - 将请求中的 Nodejs 请求转换为 React-native
问题描述
我需要转换以下请求,即 react-native 的以下代码:
节点:
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>'));
}
});
};
我已经尝试过了,但它似乎不起作用。
反应原生
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())
例如 fetch 不包含这些字段,就像我可以做的那样。
followAllRedirects: true,
jar: true,
我在哪里做错了?
解决方案
推荐阅读
- python - PyTorch - RuntimeError:具有多个值的张量的布尔值不明确
- excel - 取消过滤数据透视表中的所有行数据,然后过滤特定值
- excel - 由于编译错误,VBA Excel 无法运行:类型不匹配
- java - 为什么 JRE 10 过时而 JRE 8 是最新的?
- flutter - 如何在 Flutter 中实现底部导航抽屉
- powershell - 在 VisualStudio Code 中启动集成终端时如何附加到 PATH?
- reactjs - 在这种情况下,我将如何创建一个 React 可重用组件?
- c# - 单独使用 raycast 的激光束
- mongodb - MongoDB 文档中的集合
- if-statement - 谷歌表格 - 费用表的公式