Dart dio配置代理ip访问

  var url = '要访问的网址';
  var dio = Dio();
  //配置请求代理
  (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
      (HttpClient client) {
    client.findProxy = (uri) {
      //这里是配置代理IP
      return "PROXY  219.146.125.162:9091";
    };
    client.badCertificateCallback =
        (X509Certificate cert, String host, int port) => true;
  };
  var res = await dio.get(url, options: Options());
  if (res.statusCode == 200) {
    print('访问 成功');
  }
THE END
喜欢就支持一下吧
点赞8 分享