【问题标题】:Unrecognized functions无法识别的功能
【发布时间】:2021-01-06 07:06:39
【问题描述】:

我正在尝试向本地服务器执行 http 请求,但我收到以下 I/flutter (28338) 错误消息:状态不佳:平台不允许使用不安全的 HTTP:http: // mylocalip/auth/login,有没有人知道怎么解决的?

注意:我也在使用模块化的flutter和mobx

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, 1.22.0-10.0.pre.251, on Microsoft
    Windows [versão 10.0.19041.508], locale pt-BR)

[√] Android toolchain - develop for Android devices (Android
    SDK version 30.0.2)
[√] Android Studio (version 4.0)
[√] Connected device (1 available)

• No issues found!
I'm trying to make a request to a local http server, the request is a post for a login system that receives username and password by parameter

login() async {
try {
  var response = await http.post(http://mylocalip/auth/login,
      body: {'username': 'maximosdrr', 'password': '621251'});
  print(response.statusCode);
} catch (e) {
  print(e);
}
}

并且控制台上的输出如下:I/flutter (28338): Bad state: Insecure HTTP is not allowed by platform: http://mylocalip/auth/login

【问题讨论】:

标签: flutter flutter-http


【解决方案1】:

临时解决您的问题。首先在 res/xml(我的完整路径是/Users/dolphin/source/third-party/Cruise/android/app/src/main/res/xml) 文件夹中添加一个配置:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

然后在您的 AndroidManifest.xml 文件中添加此配置:

android:networkSecurityConfig="@xml/network_security_config"

这可能允许 http 流量。但它只是用于调试,最好的方法是使用 https 流量。更多信息:How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    • 2019-08-01
    • 2011-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多