cfug/dio

Response has unsupport header throw exception: Failed to parse header value.message

Closed this issue · 6 comments

Package

dio

Version

5.5.0+1

Operating-System

Web, Windows

Adapter

Default Dio

Output of flutter doctor -v

[√] Flutter (Channel beta, 3.24.0-0.1.pre, on Microsoft Windows [版本 10.0.22631.3880], locale zh-CN)
    • Flutter version 3.24.0-0.1.pre on channel beta at C:\work_space\flutter_sdk\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b864805a68 (7 days ago), 2024-07-23 16:06:18 -0700
    • Engine revision d89dd85f25
    • Dart version 3.5.0 (build 3.5.0-323.1.beta)
    • DevTools version 2.37.0

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

[√] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at C:\work_space\android_sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0--11609105)
    • All Android licenses accepted.

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

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.10.4)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.10.35027.167
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.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.10+0--11609105)

[√] IntelliJ IDEA Ultimate Edition (version 2024.1)
    • IntelliJ at C:\Users\xxx\AppData\Local\Programs\IntelliJ IDEA Ultimate
    • Flutter plugin version 80.0.2
    • Dart plugin version 241.18808

[√] VS Code (version 1.91.1)
    • VS Code at C:\Users\xxx\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.92.0

[√] Connected device (4 available)
    • M2102K1C (mobile) • 192.168.1.167:39257 • android-arm64  • Android 14 (API 34)
    • Windows (desktop) • windows             • windows-x64    • Microsoft Windows [版本 10.0.22631.3880]
    • Chrome (web)      • chrome              • web-javascript • Google Chrome 126.0.6478.185
    • Edge (web)        • edge                • web-javascript • Microsoft Edge 127.0.2651.74

Dart Version

3.5.0

Steps to Reproduce

Request(respose body&request body is empty):
image

Request method:
just await dio_instance.post(url)

Expected Result

normal response, i can get header from response body.

Actual Result

throw a exception, and response body is empty.

No idea what you are asking

No idea what you are asking

For this request, I can get the response header and status code information when using JavaScript.
However, when using dio to send the request and parse the response, an exception is thrown, and I cannot get any information including the status code and response header except an error message in the onError method.

The error is thrown when dio parses the response body. I want to know why the response cannot be parsed normally in dio/dart

Please provide a runnable minimal reproducible example.

Please provide a runnable minimal reproducible example.

sorry,my bad.

that is example:

      Dio dio = Dio(BaseOptions(
        baseUrl: "http://memos.w-wbr.space",
        connectTimeout: const Duration(seconds: 5),
        receiveTimeout: const Duration(seconds: 5),
      ));
      dio.interceptors.add(InterceptorsWrapper(onError: (error,handler) {
        print(error.message);
        print(error.stackTrace);
        print(error.response);
      }));
      Response? response = await dio.post("/api/v1/auth/status");
      print(response.data);

I realized that it might be a problem with the native http library. When I use the Dev tools running on a Windwos/Android device to view the request, I cannot see the response header.

The exception is thrown from the underlying HTTP foundation, rather than the dio itself.

void main() async {
  final client = HttpClient();
  final request = await client.postUrl(
    Uri.parse('http://memos.w-wbr.space/api/v1/auth/status'),
  );
  final response = await request.close();
  print(response);
}

Consider submitting the issue to the Dart SDK.