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

相关推荐
一个很帅的帅哥13 分钟前
axios(基于Promise的HTTP客户端) 与 `async` 和 `await` 结合使用
javascript·网络·网络协议·http·async·promise·await
刘志辉30 分钟前
vue传参方法
android·vue.js·flutter
安科瑞刘鸿鹏2 小时前
分布式光伏发电系统如何确保电能质量达到并网要求?
服务器·网络·分布式·嵌入式硬件·能源
去伪存真4 小时前
聊聊Flutter与原生平台通信方式(一)
前端·flutter
明天…ling4 小时前
Web前端开发
前端·css·网络·前端框架·html·web
温有情4 小时前
UDP_SOCKET编程实现
网络·网络协议·udp
MonkeyKing_sunyuhua5 小时前
安装 `privoxy` 将 Socks5 转换为 HTTP 代理
网络
pemper_5 小时前
数据不出境------IP证书申请
网络·网络协议·tcp/ip·http·https·ssl
网络研究院5 小时前
大型语言模型 (LLM) 劫持攻击不断升级,导致每天损失超过 100,000 美元
网络·人工智能·安全·语言模型·攻击·劫持
网络研究院6 小时前
企业急于采用人工智能,忽视了安全强化
网络·人工智能·安全·工具·风险·企业