错误状态:平台不允许不安全的 HTTP:

Luc*_*tos 55 connection mobile http node.js flutter

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

这是我要申请的颤振代码

这是我可以访问的后端: 我的后台代码

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

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

浏览器打印

Pra*_*ani 129

对于安卓:

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

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

android:usesCleartextTraffic="true"<application />也不要忘记采取INTERNET权限:

<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">
Run Code Online (Sandbox Code Playgroud)

对于 iOS:

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

<key>NSAppTransportSecurity</key>
<dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
</dict>
Run Code Online (Sandbox Code Playgroud)

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

谢谢你。


Mri*_*gla 53

  1. 导航到您的项目。
  2. 转到 yourapp\android\app\src\debug\AndroidManifest.xml。
  3. 添加这一行。
<application android:usesCleartextTraffic="true">
</application>
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请访问链接。


小智 15

这个问题在这里解决了。

https://flutter.dev/docs/release/break-changes/network-policy-ios-android

您只需要将 HTTP 更改为 HTTPS。像这样

响应 response = await get('https://worldtimeapi.org/api/timezone/Africa/Nairobi');


小智 6

我按照以下步骤解决了它:

  1. android/app/src/main/AndroidManifest.xml 然后写

    <application
    android:usesCleartextTraffic="true"
    android:label="laundry"
    android:icon="@mipmap/ic_launcher">
    <uses-library
     android:name="org.apache.http.legacy"
     android:required="false" />  </application>
    
    Run Code Online (Sandbox Code Playgroud)