# Flutter

> Proxyman で、Android エミュレータ、Android 実機、iOS シミュレータ、iPhone 上の Flutter アプリの HTTPS 通信をキャプチャします。コードの変更の有無は問いません。

## ✅ 1. 新しい方法 {#-1-new-solution}

> **ヒント:** Proxyman 6.4.0 以降、または Windows/Linux 3.7.0 以降で対応しています

### Android エミュレータ {#android-emulators}

Proxyman を使うと、Android エミュレータ上の Flutter アプリの HTTPS 通信をワンクリックでキャプチャできます。従来の方法と違い、Flutter のコードを変更する必要はありません。

1. Proxyman を起動し、Certificate メニュー -> Install Certificate on Android -> Emulators… を開きます。
2. 先に Android エミュレータをセットアップしてください。イメージは Google APIs のものである必要があります。

Android エミュレータの設定方法は [automatic-script-for-android-emulator.md](https://proxyman.com/docs/ja/debug-devices/android-device/automatic-script-for-android-emulator) をご覧ください。

3. 「Install Proxyman VPN on Android emulators」にチェックを入れます。
4. 「Override All Emulators」をクリックします。

![Install Proxyman VPN にチェックが入り、Override All Emulators ボタンが表示された Proxyman Android Emulator Setup Guide](https://proxyman.com/docs/assets/Screenshot%202026-01-10%20at%2019.29.46.jpg)

_Proxyman で Android エミュレータ上の Flutter アプリの HTTPS 通信をキャプチャ_

5. 新しいターミナルウィンドウが開き、エミュレータの設定を上書きする bash スクリプトが実行されます。
6. 完了すると、エミュレータに新しい VPN アプリがインストールされます。
7. VPN ボタンをタップして起動すれば完了です ✅
8. Flutter アプリを開いて HTTPS リクエストを送信してください。Proxyman がキャプチャします ✅

![Android エミュレータ上の Proxyman VPN アプリ。接続済みで、Flutter と React Native の通信を Proxyman に転送している様子](https://proxyman.com/docs/assets/Screenshot%202026-01-10%20at%2019.43.10.jpg)

## ⚠️ 2. 従来の方法 {#️-2-old-solution}

> **警告:** 従来の方法は、Proxyman macOS 6.3.0 以前、Windows/Linux 3.6.0 以前で動作します

### 2.1 問題 {#21-problem}

[Flutter はシステムレベルのプロキシを使用しない](https://github.com/flutter/flutter/issues/20376) ため、Proxyman を使用しても Flutter プロジェクトの通信が表示されない場合があります。

幸いなことに、Flutter の HTTP クライアントを設定して Proxyman をプロキシとして使用すれば、この問題を回避できます。

一般に、HTTP クライアントのすべての通信を Proxyman のプロキシサーバーに送信するように設定する必要があります。プロキシサーバーは IP = localhost、ポート = 9090 で待ち受けています。

#### 1. Flutter を設定（iOS と Android の両方で必須） {#1-set-up-flutter-required-for-all-platforms---ios--android}

手順は HTTP クライアントによって少し異なります。ここでは代表的な HTTP クライアントを取り上げます：

* Dart の [HttpClient](https://api.dartlang.org/stable/2.4.1/dart-io/HttpClient-class.html) クラス
* [http](https://pub.dev/packages/http) パッケージ
* [Dio](https://pub.dev/packages/dio)

Android エミュレータまたは iOS シミュレータを使用する場合は、`String proxy = 'localhost:9090'` を使用できます。Android 実機では、`String proxy = '<YOUR_LOCAL_IP>:9090'` を使用してください。

\<YOUR\_LOCAL\_IP> は、Proxyman の Certificate メニュー -> Install Certificate on iOS -> Physical Devices… で確認できます。

使用しているネットワークライブラリに応じて、以下の設定を使用してください：

#### Dart の HTTPClient クラス {#dart-httpclient-class}

```dart
// Make sure to replace <YOUR_LOCAL_IP> with 
// the external IP of your computer if you're using Android. 
// You can get the IP in the Android Setup Guide window
String proxy = Platform.isAndroid ? '<YOUR_LOCAL_IP>:9090' : 'localhost:9090';

// Create a new HttpClient instance.
HttpClient httpClient = HttpClient();

// Hook into the findProxy callback to set
// the client's proxy.
httpClient.findProxy = (uri) {
  return "PROXY $proxy;";
};

// This is a workaround to allow Proxyman to receive
// SSL payloads when your app is running on Android
httpClient.badCertificateCallback = (cert, host, port) => true;
```

#### HTTP パッケージ {#http-package}

```dart
// Make sure to replace <YOUR_LOCAL_IP> with 
// the external IP of your computer if you're using Android. 
// You can get the IP in the Android Setup Guide window
String proxy = Platform.isAndroid ? '<YOUR_LOCAL_IP>:9090' : 'localhost:9090';

// Create a new HttpClient instance.
HttpClient httpClient = HttpClient();

// Hook into the findProxy callback to set
// the client's proxy.
httpClient.findProxy = (uri) {
  return "PROXY $proxy;";
};

// This is a workaround to allow Proxyman to receive
// SSL payloads when your app is running on Android.
httpClient.badCertificateCallback = (cert, host, port) => true;

// Pass your newly instantiated HttpClient to http.IOClient.
IOClient myClient = IOClient(httpClient);

// Make your request as normal.
final response = myClient.get('/my-url');
```

#### Dio ≥ v5.0.0（推奨） {#dio--v500-recommended}

```dart
// Make sure to replace <YOUR_LOCAL_IP> with 
// the external IP of your computer if you're using Android. 
// You can get the IP in the Android Setup Guide window
String proxy = Platform.isAndroid ? '<YOUR_LOCAL_IP>:9090' : 'localhost:9090';

// Create a new Dio instance.
Dio dio = Dio();

dio.httpClientAdapter = IOHttpClientAdapter(
  createHttpClient: () {
    final client = HttpClient();
    client.findProxy = (uri) {
      return 'PROXY $proxy';
    };
    client.badCertificateCallback = (cert, host, port) => true;
    return client;
  },
  validateCertificate: (cert, host, port) {
    return true;
  },
); 
```

#### Dio ＜ v5.0.0（非推奨 API） {#dio--v500-deprecated-apis}

```dart
// Make sure to replace <YOUR_LOCAL_IP> with 
// the external IP of your computer if you're using Android. 
// You can get the IP in the Android Setup Guide window
String proxy = Platform.isAndroid ? '<YOUR_LOCAL_IP>:9090' : 'localhost:9090';

// Create a new Dio instance.
Dio dio = Dio();

// Tap into the onHttpClientCreate callback
// to configure the proxy just as we did earlier.
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) { 
  // Hook into the findProxy callback to set the client's proxy.
  client.findProxy = (url) {
    return 'PROXY $proxy';
  };
  
  // This is a workaround to allow Proxyman to receive
  // SSL payloads when your app is running on Android.
  client.badCertificateCallback = (X509Certificate cert, String host, int port) => true;
}
```

### 2.2 iOS シミュレータで Flutter を使用 {#22-flutter-with-ios-simulators}

1. Flutter から iOS シミュレータを起動します
2. Proxyman の Certificate メニュー -> Install Certificate on iOS -> Simulators… を開きます
3. 以下の手順をすべて実行します

![Proxyman iOS Simulators Setup。3 つの手順：Installed &#x26; Trusted の証明書、Prepare Simulators、Reboot](https://proxyman.com/docs/assets/proxyman-ios-simulators-setup.jpg)

_Proxyman 証明書を iOS シミュレータにインストールして信頼する_

4. ✅ 完了です。Proxyman で HTTPS 通信をキャプチャできます。

### 2.3 iOS 実機で Flutter を使用 {#23-flutter-with-ios-devices}

* [iOS 実機のセットアップガイド](https://proxyman.com/docs/ja/debug-devices/ios-device) に従ってください

### 2.4 Android エミュレータで Flutter を使用 {#24-flutter-with-android-emulator}

* [Android エミュレータ用の自動スクリプトガイド](https://proxyman.com/docs/ja/debug-devices/android-device/automatic-script-for-android-emulator) に従ってください

### 2.5 Android 実機で Flutter を使用 {#25-flutter-with-android-devices}

* [Android 実機のセットアップガイド](https://proxyman.com/docs/ja/debug-devices/android-device) に従ってください

#### クレジットと参考資料 {#credit--reference}

クレジット：James Dixon 氏（[https://flutterigniter.com/debugging-network-requests/](https://flutterigniter.com/debugging-network-requests/)）

## 詳細情報 {#learn-more}

* [Android エミュレータで Flutter アプリの HTTPS 通信をキャプチャする方法](https://proxyman.com/posts/Capture-https-flutter-android-emulator)
* [Flutter の iOS アプリから HTTPS 通信をキャプチャする方法](https://proxyman.com/posts/2024-11-11-capture-https-traffic-from-flutter-ios)
* [Proxyman で Flutter アプリの HTTP/HTTPS 通信をキャプチャ](https://proxyman.com/flutter)（Proxyman 公式サイト）
