【问题标题】:Flutter Http request not being executed on iOSFlutter Http请求未在iOS上执行
【发布时间】:2019-01-18 11:28:50
【问题描述】:

这是我的应用为登录用户而执行的第一个请求。在 android 上,每个请求都可以正常工作,但由于某种原因,在 iOS 上它们似乎没有被执行。我已经在模拟器上设置了开发人员选项以允许 HTTP 服务。我也在物理 iPad 上测试过代码,它不会执行请求。

在测试期间,我没有为此使用任何超时,如果我在触发请求后让代码运行一段时间,我会得到这个日志(它可能与此无关,但因为我不知道是什么,我也附上):

[C1.1 958047F2-81ED-4A34-AEDE-A23D2CD6B49F 172.20.129.134:51780<->216.58.211.42:443]
Connected Path: satisfied (Path is satisfied), interface: en0
Duration: 240.322s, DNS @0.002s took 0.008s, TCP @0.017s took 0.014s, TLS took 0.287s
bytes in/out: 4769/1077, packets in/out: 9/10, rtt: 0.016s, retransmitted packets: 1, out-of-order packets: 0

代码如下:

Future<LoginResponse> login(String login, String password, AppLocalizations locale) async {

    final response = await http.post(_url, body: {
      "module": _moduleLogin,
      "user": login,
      "pass": password,
      "lang": locale.localeName
    });

    try{
      EventManager manager = EventManager.getInstance();
      manager.clearAllEvents();
    }catch(e){
      print(e);
    }

    if (response.statusCode == 200) {
      return LoginResponse.fromJson(jsonDecode(response.body));
    } else {
      throw Exception('Failed to connect to webservice');
    }}

目前我不知道是什么导致了这个问题。我正在使用最新版本的http 软件包。

这是我的颤振医生输出:

[✓] Flutter (Channel beta, v0.9.4, on Mac OS X 10.14 18A391, locale es-ES)
    • Flutter version 0.9.4 at /Users/alex/Documents/Development/flutter
    • Framework revision f37c235c32 (4 months ago), 2018-09-25 17:45:40 -0400
    • Engine revision 74625aed32
    • Dart version 2.1.0-dev.5.0.flutter-a2eb050044

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at /Users/alex/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 27.0.3
    • ANDROID_HOME = /Users/alex/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 26.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] IntelliJ IDEA Ultimate Edition (version 2018.1.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 26.0.2
    • Dart plugin version 181.4445.29

[✓] VS Code (version 1.30.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.21.1

[✓] Connected devices (1 available)
    • iPhone XS • 5FB9A137-7AB3-46B5-94BC-9562B0E5E752 • ios • iOS 12.1 (simulator)

• No issues found!

【问题讨论】:

  • 为什么不在 Github 上填一个 bug?
  • @CopsOnRoad 可以。如果我以这种方式找到答案,我会在这里发布。
  • @FunnyStunny,你解决了这个问题吗?
  • @Sreegth 我没有。打开一个问题,我仍在等待回复。我已经在 dart-lang/http 和 flutter/flutter 中打开了它。每当我得到答案或我设法自己解决它时,都会更新这个问题。我现在正在处理其他事情,这就是为什么要花很长时间才能关闭它。
  • 在 android 上也不适用于我。即在调试时效果很好。我在 Github 上提出了一个问题,但没有回应。

标签: ios http dart flutter


【解决方案1】:

想出了一个解决方案,即使我不知道它为什么会起作用。

我用dio 包替换了http 包,它在两个平台上都运行良好。

【讨论】:

    猜你喜欢
    • 2020-06-02
    • 2020-02-09
    • 1970-01-01
    • 2011-07-29
    • 1970-01-01
    • 2019-10-21
    • 1970-01-01
    • 1970-01-01
    • 2022-01-17
    相关资源
    最近更新 更多