# React Native

> 使用 Proxyman 抓取 React Native 和 Expo 应用的 HTTPS 流量，支持 iOS 真机、iOS 模拟器、Android 真机和 Android 模拟器。

## 视频 {#video}

[在 iOS 模拟器和 Android 模拟器上抓取 React Native Expo 应用的 HTTPS 流量](https://www.youtube.com/watch?v=4LkKXyIPulM)

## 1. React Native - iOS {#1-react-native---ios}

* 如果你的 iOS 应用使用 React Native 开发，请参照 iOS 指南操作，与原生 iOS 应用没有区别。
* 支持 Expo 和 Metro bundler

- [iOS 真机](https://proxyman.com/docs/zh-cn/debug-devices/ios-device)

- [iOS 模拟器](https://proxyman.com/docs/zh-cn/debug-devices/ios-simulator)

## 2. React Native - Android {#2-react-native---android}

React Native 的 Android 应用抓取 HTTP/HTTPS 流量的方式与原生 Android 应用相同。请参照 Android 设置指南操作：

* [Android 真机](https://proxyman.com/docs/zh-cn/debug-devices/android-device)
* [Android 模拟器](https://proxyman.com/docs/zh-cn/debug-devices/android-device/automatic-script-for-android-emulator)

> **注意:** 请确保完整按照指南中的所有步骤操作，尤其是**第 5 步**，即添加 **res/xml/network\_security\_config.xml** 和 **AndroidManifest.xml**。
>
> 否则，Proxyman 无法解密 SSL 连接。

## 3. 故障排查 - Android {#3-troubleshooting---android}

### 3.1 Metro bundle 错误 {#31-metro-bundle-errors}

在 Android 设备上将 HTTP Proxy 设置为 Proxyman 后，由于 Metro bundler 无法连接到其本地服务器，你可能会遇到以下错误。

![Android 上 React Native 的红屏错误：Unable to load script, make sure you're running Metro](https://proxyman.com/docs/assets/Screenshot%202023-04-06%20at%2007.58.01.png)

_Metro bundle 错误_

解决方法如下：

#### Android 模拟器 {#android-emulator}

1. 打开 Proxyman -> Certificate 菜单 -> Install Certificate on Android -> Emulators… -> 点击 “Revert All Changes”
2. 打开 Android 模拟器，进入 Settings 应用 -> Network -> Wi-Fi -> 打开代理设置
3. 使用 **Proxyman IP & Port** 手动设置 HTTP Proxy。如果不知道 IP 和端口，请打开 Certificate 菜单 -> Install Certificate on Android -> Physical Devices…，并在第 2 步中找到 Server IP & Port。
4. 保存之前，在绕过代理列表（bypass proxy list）中输入 `localhost` ✅

![Android Wi-Fi 代理设置，包含 Proxyman IP 和端口，以及绕过代理列表中的 localhost](https://user-images.githubusercontent.com/5878421/230129476-4bd5d1a0-c3c5-4c73-bb79-81f14a071e63.jpg)

5. 完成
6. `The Bridge Was shutdown` 警告和 Metro bundle 错误已消失 ✅

#### Android 真机 {#android-physical-device}

1. 在 Android 真机上打开 Settings 应用 -> Network -> Wi-Fi -> 打开代理设置
2. 使用 Proxyman IP & Port 手动设置 HTTP Proxy。如果不知道 IP 和端口，请打开 Certificate 菜单 -> Install Certificate on Android -> Physical Devices…，并在第 2 步中找到 Server IP & Port。
3. 保存之前，在绕过代理列表中输入 `your IP` ✅ 
4. 完成

更多内容请见：[https://github.com/ProxymanApp/Proxyman/issues/1407#issuecomment-1497235102](https://github.com/ProxymanApp/Proxyman/issues/1407#issuecomment-1497235102)

## 了解更多 {#learn-more}

* [如何抓取 Expo React Native iOS 和 Android 应用的 HTTP/HTTPS 流量](https://proxyman.com/posts/how-to-capture-https-from-React-native-app-2025-update)
* [使用 Proxyman 抓取 React Native 应用的 HTTPS 流量](https://proxyman.com/posts/2023-09-25-Capture-HTTPs-Requests-From-React-Native-Apps)
* [使用 Proxyman 抓取 React Native 应用的 HTTP/HTTPS 流量](https://proxyman.com/react-native)（Proxyman 官网）
