错误状态:平台不允许不安全的 HTTP: [英] Bad state: Insecure HTTP is not allowed by platform:

查看:43
本文介绍了错误状态:平台不允许不安全的 HTTP:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以下问题:E/flutter (7144): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] 未处理的异常:错误状态:平台不允许不安全的 HTTP:http://myIPv4:PORT/PATH.

I'm having the following problem: E/flutter ( 7144): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Bad state: Insecure HTTP is not allowed by platform: http://myIPv4:PORT/PATH.

这是我可以访问的后端:

And this is the backend that I can access:

我已经允许 cors 访问,但即使这对我也没有帮助.我已经尝试使用 http://localhost:port/path 和 http://myIP:port/path 但没有用!

I already allowing the access by cors, but not even this help me. I already tried to use the http://localhost:port/path and http://myIP:port/path but doesn't worked!

但如果我尝试通过浏览器直接访问,那么工作.

But if I try access directly by browser so work.

推荐答案

Android:

以下迁移指南可能会省略此行为:https://flutter.dev/docs/release/break-changes/network-policy-ios-android.

或...只需添加android/app/src/main/AndroidManifest.xml:

or... Just add in android/app/src/main/AndroidManifest.xml:

android:usesCleartextTraffic="true" 也不要忘记获得 INTERNET 许可:

android:usesCleartextTraffic="true" to <application /> also dont forget to take INTERNET PERMISSION:

<uses-permission android:name="android.permission.INTERNET" /> <!-- This Line -->

<application
        android:name="io.flutter.app.FlutterApplication"
        android:label="receipt"
        android:usesCleartextTraffic="true" <!-- This Line -->
        android:icon="@mipmap/ic_launcher">

对于 iOS:

在 iOS 上的应用程序中全局允许不安全/HTTP 请求,您可以将其添加到您的 ios/Runner/info.plist 主字典定义下:

<key>NSAppTransportSecurity</key>
<dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
</dict>

请注意,启用此功能时您需要向 Apple 的审核团队提供解释,否则您的应用将在提交时被拒绝.

Be warned that you will need to have an explanation for Apple's review team when enabling this, otherwise your app will get rejected on submission.

谢谢.

这篇关于错误状态:平台不允许不安全的 HTTP:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆