dio icon indicating copy to clipboard operation
dio copied to clipboard

Flutter混编iOS的时候dio请求会超时

Open cxycwz opened this issue 6 years ago • 9 comments

服务器这边返回正常的,原生框架去请求同一个接口,每次都会成功,使用flutter部分调用dio去请求则会出现timeout,10次请求,会有一两次timeout。针对iOS会有额外的dio配置方案吗?协议为https,但为忽略证书验证的

cxycwz avatar Aug 03 '20 03:08 cxycwz

我在网络上也搜到了类似的问题,https://gitmemory.com/issue/flutterchina/dio/349/506129938 目前还没找到相应的解决方案

cxycwz avatar Aug 03 '20 03:08 cxycwz

报超时的时候,栈错误

┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>
│ \^[[0m\^[[39m\^[[48;5;196mDioError [DioErrorType.CONNECT_TIMEOUT]: Connecting timed out [10000ms]<…>
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…>
│ #0   Http._interceptorConf.() (package:carmodule/common/network/http.dart:106:9<…>
│ #1   InterceptorsWrapper.onError (package:dio/src/interceptor.dart:125:2<…>
│ #2   DioMixin._request._errorInterceptorWrapper.() (package:dio/src/dio.dart:867:4<…>
│ #3   _rootRunUnary (dart:async/zone.dart:1192:3<…>
│ #4   _CustomZone.runUnary (dart:async/zone.dart:1085:1<…>
│ #5   _FutureListener.handleError (dart:async/future_impl.dart:159:2<…>
│ #6   Future._propagateToListeners.handleError (dart:async/future_impl.dart:694:4<…>
│ #7   Future._propagateToListeners (dart:async/future_impl.dart:715:2<…>
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…>
│ ⛔ msg:Connecting timed out [10000ms], api: /order/payType<…>
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>

服务器的响应的时间远小于10秒

相关dio的配置及使用如下:

class Http {
  static Dio _dio;

  /// doc: https://github.com/flutterchina/dio/blob/flutter/README-ZH.md
  static Dio _getDio() {
    if (_dio == null) {
      _dio = Dio(BaseOptions(
          baseUrl: Strings.srvUrl, 
          connectTimeout: 10000, 
          receiveTimeout: 5000, 
          contentType: ContentType.json.toString()));
      _dio.interceptors.addAll(_interceptorConf());
    }
    return _dio;
  }

  ///Http请求拦截器配置
  static Iterable<Interceptor> _interceptorConf() {
    return [
      LogInterceptor(logPrint: (obj) => LogUtil.i(obj)), //添加日志拦截器
      InterceptorsWrapper(onRequest: (RequestOptions options) async {
        // ... 一些全局参数补充、参数加密
        return options;
      }, onResponse: (Response response) async {
        // ... 一些数据解密
        return response;
      }, onError: (DioError e) async {
        // 当请求失败时做一些预处理
        LogUtil.e('msg:${e.message}, api: ${e?.request?.path}', error: e, stackTrace: StackTrace.current);
        return e; //continue
      })
    ];
  }

  static Future<Resp> doPost(String path, Map<String, dynamic> params) async {
    Resp respData;
    try {
      Response response = await _getDio().post(
        path,
        data: params,
      );
      respData = Resp.fromJson(response.data);
    } on DioError catch (e) {
      // 当请求失败时做一些处理
    }
    return respData;
  }
}

cxycwz avatar Aug 03 '20 04:08 cxycwz

mark,遇到同样的问题

peterlpt avatar Aug 03 '20 10:08 peterlpt

mark,遇到同样的问题

heimabailang avatar Aug 31 '20 08:08 heimabailang

mark,遇到同样的问题

heimabailang avatar Sep 02 '20 04:09 heimabailang

mark,遇到同样的问题

heimabailang avatar Sep 02 '20 08:09 heimabailang

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

stale[bot] avatar Oct 03 '20 04:10 stale[bot]

same issue

icespring avatar Dec 23 '20 07:12 icespring

same issue

nEdAy avatar Jan 28 '21 02:01 nEdAy