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

相关推荐
神鸟云1 小时前
DELL服务器 R系列 IPMI的配置
linux·运维·服务器·网络·边缘计算·pcdn
herderl2 小时前
**僵尸进程(Zombie Process)** 和**孤儿进程(Orphan Process)**
linux·运维·服务器·网络·网络协议
亲爱的非洲野猪2 小时前
令牌桶(Token Bucket)和漏桶(Leaky Bucket)细节对比
网络·算法·限流·服务
G_H_S_3_2 小时前
【网络运维】Playbook项目实战:基于 Ansible Playbook 一键部署 LNMP 架构服务器
linux·运维·服务器·网络·ansible
七七&55612 小时前
2024年08月13日 Go生态洞察:Go 1.23 发布与全面深度解读
开发语言·网络·golang
元清加油12 小时前
【Golang】:函数和包
服务器·开发语言·网络·后端·网络协议·golang
书弋江山13 小时前
flutter 跨平台编码库 protobuf 工具使用
android·flutter
程序员老刘·13 小时前
Flutter 3.35 更新要点解析
flutter·ai编程·跨平台开发·客户端开发
tangweiguo0305198713 小时前
Flutter vs Android:页面生命周期对比详解
flutter
tangweiguo0305198713 小时前
Flutter网络请求实战:Retrofit+Dio完美解决方案
flutter