目录

How do I use Charles to capture packets for debugging HarmonyOS atomic services?

When configuring the environment, you must select Allow in the window displayed by Charles on the computer to connect to the mobile phone.

When downloading a certificate, you need to add http://chls.pro/ssl to the link. After the certificate is downloaded, save it to the common directory Download.

To use Charles to capture packets, perform the following steps:

1. Connect the mobile phone and PC/2-in-1 device to the same LAN. When the mobile phone connects to the Wi-Fi network, tap Proxy Settings (Manual) and set the proxy IP address and port to the port listened by Charles.

2. To set the proxy, do the following:

(1) Choose Proxy > SSL Proxy Settings and add *:* and *:443 to Include.

(2) Choose Proxy > Proxy Settings and select Enable transparent HTTP proxying.

3. Export the certificate from Charles on the PC/2-in-1 device and choose Help > SSL Proxying > Install Charles Root Certificate on a Mobile Device or Remote Browser.

4. Import the system root certificate to the mobile phone.

(1) Use the mobile phone browser to download the certificate from the website provided by Charles. After the certificate is downloaded using the browser, save it to the download directory.

(2) Run hdc shell aa start -a MainAbility -b com.ohos.certmanager to start the certificate installer.

(3) Select Install from storage and specify the PEM certificate.

5. To install the Charles certificate in the system trusted directory of the PC/2-in-1 device, do the following:

Choose Help > SSL Proxying > Install Charles Root Certificate, install the certificate, and select Trusted Root Certification Authorities as the certificate storage path.

6. Start Charles to capture packets.