坏状态:平台不允许使用不安全的HTTP: [英] Bad state: Insecure HTTP is not allowed by platform:
问题描述
我遇到以下问题: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/breaking-changes/network-policy-ios-android .
或...只需添加 android/app/src/main/AndroidManifest.xml:
or... Just add in android/app/src/main/AndroidManifest.xml:
android:usesCleartextTraffic ="true"
到< application/>
的同时,也不要忘记使用 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屋!