如何解决Flutter http.post Future 在不同的模拟器上给出不同的错误或什么都不回
我有这个 Future,它可以作为一个普通的登录表单, 前段时间还可以完美运行,但现在出现了一些问题。
当我在 chrome 上启动它时,它只在我在 URL 上使用这个额外的 cors 部分时才有效,因为如果我不写它,我会得到这个:错误:XMLHttpRequest 错误.. 当我在像素模拟器上启动它时,它什么也没回。 当我在真正的三星设备上启动它时,它仅在我切掉 URL 的 cors 部分时才起作用,否则它会给我这个错误:缺少所需的请求标头。必须指定以下之一:origin,x-requested-with
而且 php 脚本工作正常
有人对这个问题有答案吗?
Future<String> senddata() async {
print(passwort.text);
print(eMail.text);
final response =
await http.post("https://cors-anywhere.herokuapp.com/https://www.nothinghere.de/2/StillNothing.php",body: {
"eMail": eMail.text,"passwort": passwort.text,});
print(response.body);
var datauser = json.decode(response.body);
var key = datauser["key"];
var id = datauser["id"];
var lol = response.body;
if(key==69){
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setInt('token',key);
prefs.setString('id',id);
Navigator.push(
context,MaterialPageRoute(builder: (context) => Schueler()),);
}
return lol;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。