cfug / dio

A powerful HTTP client for Dart and Flutter, which supports global settings, Interceptors, FormData, aborting and canceling a request, files uploading and downloading, requests timeout, custom adapters, etc.
https://dio.pub
MIT License
12.46k stars 1.51k forks source link

Dio cannot resolve hostname http://127.0.0.1.lambdatest:port #2119

Closed renehw closed 6 months ago

renehw commented 7 months ago

Package

dio

Version

5.4.1

Operating-System

Android

Output of flutter doctor -v

flutter doctor -v
[√] Flutter (Channel stable, 3.19.0, on Microsoft Windows [versÆo 10.0.22631.3155], locale pt-BR)
    • Flutter version 3.19.0 on channel stable at C:\Users\HansBoron\APPs\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision bae5e49bc2 (8 days ago), 2024-02-13 17:46:18 -0800
    • Engine revision 04817c99c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\HansBoron\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop Windows apps
    X Visual Studio not installed; this is necessary to develop Windows apps.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2023.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)

[√] VS Code (version 1.86.2)
    • VS Code at C:\Users\HansBoron\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.82.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [versÆo 10.0.22631.3155]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 121.0.6167.185
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 121.0.2277.128

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Dart Version

3.3.0

Steps to Reproduce

The test form is a little complicated.

We are currently using the Lambdatest tool to perform manual tests using physical devices remotely.

To make the connection, we use a tool they provide called Underpass and in the app we use the url 'http://127.0.0.1.lambdatest:port'. The port refers to our local REST API.

Using this tool we do not obtain results, returning generic errors or timeouts.

We tested creating a native app with Kotlin using the Retrofit library for HTTP connections and we were successful.

Expected Result

A successful return is expected

Actual Result

Unhandled Dio errors or SocketException and Timeout

hansmboron commented 7 months ago

I have the same problem when trying to run an app with dio in the lambdaTest tunnel image

Lewiz-QA commented 7 months ago

Me too, when I try to use a Flutter App on LambdaTest using a local backend over UnderPass tunnel, I face the DioExceptions "errno=7" or "errno=111", which are very generic to identify what's the main cause of the problem. One important point is that the same request that didn't run on app, works fine on Chrome present in some Real Device of LambdaTest.

AlexV525 commented 7 months ago

Is the service running on the device? If not, use the ip of your host device to access.

renehw commented 7 months ago

Does not work with local device IP. This device is accessed remotely.

AlexV525 commented 7 months ago

I'm not following here. Is 127.0.0.1 targeting the same device as where the Flutter app runs? Such as you are running Flutter on an Android device, but trying to access the 127.0.0.1.lambdatest on a macOS device.

renehw commented 7 months ago

We discovered in our tests that using https://pub.dev/packages/native_dio_adapter the problem does not occur. Using native_dio_adapter, we were able to connect the remote mobile device to our QA machine without any problems.

However, despite having managed to solve this problem, I believe there is a problem when using http Dart. As native_dio_adapter uses a native library for HTTP requests, the problem does not occur. I suggest carrying out a review at this point.

For now, the problem we were having is resolved.

AlexV525 commented 7 months ago

We cannot make any review until a detailed example is provided. I'm still not sure about the environment as I mentioned above:

I'm not following here. Is 127.0.0.1 targeting the same device as where the Flutter app runs? Such as you are running Flutter on an Android device, but trying to access the 127.0.0.1.lambdatest on a macOS device.