flutter dio使用proxyman抓包进行网络调试

证书

wifi

手机和电脑连上同一个wifi,并且手机wifi使用代理,代理地址为电脑的ip和proxyman设置的监听端口

代码

dart 复制代码
import 'package:dio/dio.dart';
import 'package:dio/io.dart';
import 'dart:io';

class ProxyUtil {
  static String proxyIP = "";
  static String proxyPort = "9090";

  static Dio useProxy(Dio dio) {
    if (proxyIP == "") return dio;
    dio.httpClientAdapter = IOHttpClientAdapter(
      createHttpClient: () {
        final client = HttpClient();
        client.findProxy = (uri) {
          // Proxy all request to localhost:8888.
          // Be aware, the proxy should went through you running device,
          // not the host platform.
          return 'PROXY $proxyIP:$proxyPort';
        };
        client.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
        return client;
      },
    );
    return dio;
  }
}

使用方式

dart 复制代码
Dio dio = Dio();
ProxyUtil.useProxy(dio);

proxyIP为电脑ip

相关推荐
未来之窗软件服务34 分钟前
自己平台接入国家网络身份认证公共服务接入
网络·仙盟创梦ide·东方仙盟
要做一个小太阳43 分钟前
华为Atlas 900 A3 SuperPoD 超节点网络架构
运维·服务器·网络·华为·架构
ujainu1 小时前
Flutter + OpenHarmony 游戏开发进阶:游戏主循环——AnimationController 实现 60fps 稳定帧率
flutter·游戏·openharmony
2601_949868361 小时前
Flutter for OpenHarmony 剧本杀组队App实战04:发起组队表单实现
开发语言·javascript·flutter
vx-bot5556661 小时前
企业微信接口在混合云环境下的集成架构与网络互联方案企业微信接口在混合云环境下的集成架构与网络互联方案
网络·架构·企业微信
蒸蒸yyyyzwd1 小时前
c网络编程学习笔记
c语言·网络·学习
kirk_wang1 小时前
Flutter艺术探索-Flutter在鸿蒙端运行原理:OpenHarmony平台集成
flutter·移动开发·flutter教程·移动开发教程
时艰.1 小时前
Java 并发编程:Callable、Future 与 CompletableFuture
java·网络
晚霞的不甘1 小时前
Flutter for OpenHarmony专注与习惯的完美融合: 打造你的高效生活助手
前端·数据库·经验分享·flutter·前端框架·生活
强风7942 小时前
Linux—应用层自定义协议与序列化
运维·服务器·网络