network_module.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import 'package:dio/dio.dart';
  2. final defaultDio = Dio(BaseOptions(
  3. /// 发送数据的超时设置。
  4. ///
  5. /// 超时时会抛出类型为 [DioExceptionType.sendTimeout] 的
  6. /// [DioException]。
  7. ///
  8. /// `null` 或 `Duration.zero` 即不设置超时。
  9. //Duration ? sendTimeout;
  10. /// 接收数据的超时设置。
  11. ///
  12. /// 这里的超时对应的时间是:
  13. /// - 在建立连接和第一次收到响应数据事件之前的超时。
  14. /// - 每个数据事件传输的间隔时间,而不是接收的总持续时间。
  15. ///
  16. /// 超时时会抛出类型为 [DioExceptionType.receiveTimeout] 的
  17. /// [DioException]。
  18. ///
  19. /// `null` 或 `Duration.zero` 即不设置超时。
  20. //Duration ? receiveTimeout;
  21. /// 可以在 [Interceptor]、[Transformer] 和
  22. /// [Response.requestOptions] 中获取到的自定义对象。
  23. //Map<String, dynamic> ? extra;
  24. /// HTTP 请求头。
  25. ///
  26. /// 请求头的键是否相等的判断大小写不敏感的。
  27. /// 例如:`content-type` 和 `Content-Type` 会视为同样的请求头键。
  28. //Map<String, dynamic> ? headers;
  29. /// 是否保留请求头的大小写。
  30. ///
  31. /// 默认值为 false。
  32. ///
  33. /// 该选项在以下场景无效:
  34. /// - XHR 不支持直接处理。
  35. /// - 按照 HTTP/2 的标准,只支持小写请求头键。
  36. //bool ? preserveHeaderCase;
  37. /// 表示 [Dio] 处理请求响应数据的类型。
  38. ///
  39. /// 默认值为 [ResponseType.json]。
  40. /// [Dio] 会在请求响应的 content-type
  41. /// 为 [Headers.jsonContentType] 时自动将响应字符串处理为 JSON 对象。
  42. ///
  43. /// 在以下情况时,分别使用:
  44. /// - `plain` 将数据处理为 `String`;
  45. /// - `bytes` 将数据处理为完整的 bytes。
  46. /// - `stream` 将数据处理为流式返回的二进制数据;
  47. //ResponseType? responseType;
  48. /// 请求的 content-type。
  49. ///
  50. /// 请求默认的 `content-type` 会由 [ImplyContentTypeInterceptor]
  51. /// 根据发送数据的类型推断。它可以通过
  52. /// [Interceptors.removeImplyContentTypeInterceptor] 移除。
  53. //String? contentType;
  54. /// 判断当前返回的状态码是否可以视为请求成功。
  55. //ValidateStatus? validateStatus;
  56. /// 是否在请求失败时仍然获取返回数据内容。
  57. ///
  58. /// 默认为 true。
  59. //bool? receiveDataWhenStatusError;
  60. /// 参考 [HttpClientRequest.followRedirects]。
  61. ///
  62. /// 默认为 true。
  63. //bool? followRedirects;
  64. /// 当 [followRedirects] 为 true 时,指定的最大重定向次数。
  65. /// 如果请求超出了重定向次数上线,会抛出 [RedirectException]。
  66. ///
  67. /// 默认为 5。
  68. //int? maxRedirects;
  69. /// 参考 [HttpClientRequest.persistentConnection]。
  70. ///
  71. /// 默认为 true。
  72. //bool? persistentConnection;
  73. /// 对请求内容进行自定义编码转换。
  74. ///
  75. /// 默认为 [Utf8Encoder]。
  76. //RequestEncoder? requestEncoder;
  77. /// 对请求响应内容进行自定义解码转换。
  78. ///
  79. /// 默认为 [Utf8Decoder]。
  80. //ResponseDecoder? responseDecoder;
  81. /// 当请求参数以 `x-www-url-encoded` 方式发送时,如何处理集合参数。
  82. ///
  83. /// 默认为 [ListFormat.multi]。
  84. //ListFormat? listFormat;
  85. ));