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

证书

flutter dio使用proxyman抓包进行网络调试_第1张图片

wifi

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

代码

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;
  }
}

使用方式

Dio dio = Dio();
ProxyUtil.useProxy(dio);

proxyIP为电脑ip

你可能感兴趣的:(flutter,网络)