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

相关推荐
AuroraDPY12 分钟前
计算机网络:Socket编程预备
网络·计算机网络
listhi5204 小时前
Vue.js 3的组合式API
android·vue.js·flutter
起风了___4 小时前
Flutter 多端音频控制台:基于 audio_service 实现 iOS、Android 锁屏与通知中心播放控制
前端·flutter
国服第二切图仔7 小时前
Rust开发之错误处理与日志记录结合(log crate使用)
网络·算法·rust
leinchu7 小时前
Flutter + Codebuddy的坑
flutter
天***88967 小时前
驱动精灵、驱动人生、NVIDIA专业显卡驱动、360驱动大师、联想乐驱动,电脑驱动修复工具大全
网络·电脑·负载均衡
AORO20257 小时前
三防平板三防是指哪三防?适合应用在什么场景?
服务器·网络·智能手机·电脑·1024程序员节
王道长服务器 | 亚马逊云8 小时前
AWS + SeyouCMS:海外资源站的高性能部署实战
服务器·网络·数据库·云计算·软件构建·aws
泷羽Sec-静安8 小时前
Less-7 GET-Dump into outfile-String
android·前端·网络·sql·安全·web安全
、BeYourself9 小时前
【随机访问介质访问控制-1】为什么纯 ALOHA 效率不到 20%?3 大随机访问 MAC 协议拆解
网络·计算机网络·数据链路层