Dio: responseBody.headers

Created on 22 Sep 2019  ·  3Comments  ·  Source: flutterchina/dio

New Issue Checklist

  • [+] I have searched for a similar issue in the project and found none

Issue Info

| Info | Value | |
| ------------------------------ | ----------------------------------------------------- | ---- |
| Platform Name | flutter / ios | |
| Platform Version | 1.10.6-pre.29 / 13.0 | |
| Dio Version | 3.0.1 | |
| Android Studio / Xcode Version | Xcode 11.0 (11A420a) | |
| Repro rate | all the time (100%) | |

Issue Description and Steps

dio source code where exception occurs: lib/src/dio.dart

var headers =
  Headers.fromMap(responseBody.headers ?? Map<String, String>());

real responseBody.headers (please notice value:List):

0:"x-amzn-requestid" -> List (1 item)
  key:"x-amzn-requestid"
  value:List (1 item)
    [0]:"47a24431-9ff9-4ef2-8ce3-267387891999"
...
...
...

stringify version of headers:

{
  x-amzn-requestid: [47a24431-9ff9-4ef2-8ce3-267387891999],
  connection: [keep-alive],
  date: [Sun, 22 Sep 2019 16:33:34 GMT],
  x-amzn-trace-id: [Root=1-5d87a25e-8a0546500fa9a25997c84c04;Sampled=0],
  content-length: [105],
  x-amz-apigw-id: [AbZOwFYiliAFYRA=],
  content-type: [application/json]
}

Error:
type 'List<String>' is not a subtype of type 'String'

The following code of mine induces such a faulty result:

final BaseOptions dioOpts = BaseOptions(
  method: 'POST',
  connectTimeout: 1000,
  sendTimeout: 1000,
  receiveTimeout: 1000,
  baseUrl: 'https://**********.execute-api.eu-central-1.amazonaws.com/prod',
  headers: {
    HttpHeaders.userAgentHeader: '*********',
    HttpHeaders.acceptCharsetHeader: 'utf-8',
    HttpHeaders.acceptEncodingHeader: 'gzip,compress,deflate,br',
    HttpHeaders.acceptHeader: '*/*',
    HttpHeaders.acceptLanguageHeader: 'en-US',
    HttpHeaders.contentTypeHeader: 'application/json; charset=utf-8',
    'API': '0.0.0',
  },
  contentType: Headers.jsonContentType,
  responseType: ResponseType.json,
);
final String requiestPath = '/';
final Dio dio = Dio(dioOpts);

final Response response = await dio.request(
  requiestPath,
  data: {
    'code': action.code,
  },
);

Most helpful comment

Dio Version 3.0.3 still has the error type 'List' is not a subtype of type 'String' @wendux

All 3 comments

@wendux, why have you closed this?

Dio Version 3.0.3 still has the error type 'List' is not a subtype of type 'String' @wendux

Was this page helpful?
0 / 5 - 0 ratings