Painted painted levels: fostered fostered fostered

“Charles Certificate” for iOS HTTPS packet capture by Xs·H


During iOS application development, packet capture is often used to debug service interfaces. Charles and Wireshark are the two most commonly used software in the iOS development process.

In daily development, we don’t see what is being sent and received between the application and the server, and without this visibility, it can be very difficult and time-consuming to determine the exact location of a failure. Charles is a Web proxy running on a PC. By configuring the application to access the network through Charles, all data sent and received can be recorded and displayed on Charles, which can greatly improve the efficiency of the debugger. Charles’s official website

Charles’s role can be seen below:

Charles has the following common functions:

  • Request preview: Preview and filter request data through group or sequence views;
  • Request packet capture: Capture HTTP and HTTPS request data and response data.
  • Request breakpoint: intercepts the specified request or response and previews the data in the middle;
  • Data modification: modify request data and response data to match data testing;
  • Request resend: Specifies that requests be sent repeatedly to test backend functionality and performance;
  • Network speed simulation: Set network speed delay to simulate 2G/3G/4G networks on mobile phones;

Since Charles has many functions, it is difficult to introduce it in detail in this paper. Therefore, the author takes the use of Charles in projects as the starting point and introduces several of the most commonly used and useful functions.

A, install,

Charles is a paid app. It has a free 30-day trial period, after which it will be forced back every 30 minutes and can be used again after a restart. The Charles installation package can be obtained from the Charles website, and the cracked version can also be found on the Internet.

Download crack version should pay attention to identify installation package source, beware of Trojan and virus.

Request a preview

Once Charles is started, it runs in packet capture mode. Since Charles will automatically configure the proxy for the PC browser, you can preview the request information by opening any web page (as long as there is a network request).

If you use a plug-in to set up an independent proxy for your browser, close the plug-in or set it to a system proxy.

Charles provides two preview modes, Structure and Sequence. Structure group requests by domain name, which can easily preview the request data under the same domain name, and also facilitate the analysis and processing of a service interface in daily development. The picture is as follows:

Sequence Displays request information in chronological order to preview the request information directly. In this mode, you can use the Filter to Filter requests for specific analysis. The picture is as follows:

In both modes, you can preview different types of Request information by switching labels (Overview, Request, Response, etc.). Under the most commonly used Request and Response tags, you can also preview the details of the corresponding tags by switching the child tags (Headers, Cookies, Text, etc.). The picture is as follows:

Request packet capture

Using the white circle and red dot button on the toolbar (the shortcut key is “Command+R”), Charles can switch between Recording and Stop Recording. Use this button to enable the packet capture function when debugging is required. This button can effectively reduce interference information and quickly capture the request to be debugged.

To capture packets sent from a mobile phone (iPhone for example), ensure that the iPhone and PC work on the same LAN.

1. Obtain the IP address of the PC

On the Charles menu bar, choose Help > Local IP Address to view the IP Address of the PC. The picture is as follows:

You can also run the ifconfig en1 command on the Mac terminal to view the IP address of the PC. The picture is as follows:

2. Configure the iPhone agent

Enter the IP address of the PC in the server input box, and enter the proxy port of Charles in the port input box (usually 8888). The picture is as follows:

The specific port can be viewed from the Charles menu bar -> Proxy -> Proxy Settings. The picture is as follows:

Once the iPhone agent configuration is complete, Charles will pop up a connection prompt. After clicking Allow, you can use Charles to capture packets for requests from that iPhone. The picture is as follows:

3. Capture HTTPS requests

After configuring the iPhone agent, you can preview the HTTP request data through the Structure or Sequence window. However, because the HTTPS request is encrypted, only garbled data can be viewed when previewing the request. To preview the data plaintext of the HTTPS request, PC and iPhone installation certificate authorization is required.

1) PC installation certificate

Charles Root Certificate can be installed on the Charles menu bar -> Help -> SSL Proxying -> Install Charles Root Certificate. The Certificate can be viewed in the Mac keystring. The picture is as follows:

The certificate can be viewed in the keystring of the Mac. Double-click the certificate to set the trust permission to always trust. The picture is as follows:

2) iPhone installation certificate

In the iPhone browser visit http://charlesproxy.com/getssl certificate can be downloaded and installed. This address usually does not change, You can Install Charles Root Certificate on a Mobile Device or Remote on the Charles menu bar -> Help -> SSL Proxying -> Install Charles Root Certificate on a Mobile Device or Remote In Browser, you can view the latest official certificate download address. The picture is as follows:

After installing and trusting the certificate, go to iPhone Settings > About Native > Certificate Trust Settings to enable the root certificate. The picture is as follows:

In this way, you can use Charles to capture the HTTPS requests made by the iPhone and preview the plaintext data.

To make HTTPS requests on the packet capture simulator, click Install Charles Root Certificate in iOS Simulators.

3) Enable SSL permission for packet capture

On the Charles menu bar, choose Proxy > SSL Proxying Settings, select Enable SSL Proxying, and then add the Host and Port that need to capture packets to Locations. The picture is as follows:

You can also right-click a request or group on the packet capture page and click Enable SSL Proxying in the options list. The picture is as follows:

4. Request breakpoints

In Charles’s request preview screen, right-click on a request/group and the Breakpoints option pops up in the list of options. The picture is as follows:

Clicking Breakpoints sets a breakpoint for the request. By default, the Request/Response process of the Request is controlled by breakpoints, that is, the Request data will be paused before it is sent to the server, and the Response data will be paused before it is sent to the client. You can edit Breakpoint parameters from the Charles menu bar -> Proxy -> Breakpoint Settings. For example, if you only need to add a breakpoint to the Response process, you can cancel the check status of Request. The picture is as follows:

In the breakpoint state, you can preview and modify the request’s intermediate data before clicking the Unexecute button to continue executing the request.

5. Data modification

Both Rewrite and Breakpoint Editing can be used to modify request data.

1. Rewrite

In the Charles menu bar -> Tools -> Rewrite, you can enable the Rewrite function. Click the Add button to Add a setting. In the Locations and Rules Locations on the right, you can Add the request path to Rewrite and the Rewrite rule. The picture is as follows:

Rewrite is suitable for bulk and long-term changes to requests that have a significant impact on request data (rules are often forgotten after testing). So, in some lightweight data modification scenarios, I often modify data in conjunction with Breakpoint.

2. Breakpoint Editing

Combined with the breakpoint function, the Request/Response data can be modified temporarily. When a breakpoint is set for a request, the breakpoint window is automatically jumped when the request occurs. Click on the Edit Request/Response interface to see the information in the middle, and select the appropriate data format (HTML, Json, etc.) for modification. After the modification is complete, click the Execute button to see the modified effect on the terminal. The picture is as follows:

Request for resend

In Charles’ request preview interface, right-click a request/group, and two options Repeat and Advanced Repeat are displayed in the option list. The picture is as follows:

Clicking Repeat will send the request again, which is often used to test whether the service interface can be accessed properly and whether the client can receive the returned data. Click Advanced Repeat to display the edit page for resend parameters, as shown below:

In this editing interface, you can customize Iterations, Concurrency, and Repeat, which are commonly used to stress test service interfaces.

Seven, network speed simulation

On the Charles menu bar -> Proxy -> Throttle Settings, you can enable Throttling and customize Locations (restricted service interface) and Throttle Configuration (Throttling Configuration). Support for Throttle Preset data transmission mode, Bandwidth Utilisation, round-trip latency, MTU Reliability Stability and other parameters. In Throttle PRESET, THE SIMULATION of 3G/4G network environment is supported. The picture is as follows:

Using Throttle function, you can conveniently arrange the bugs caused by the network, but such bugs are easy to appear online, and it is difficult to troubleshoot and reproduce.


Recommended articles:

TCP preliminary IP UDP iOS multi-thread thread safety iOS multi-thread GCD iOS multi-thread NSOperation iOS multi-thread NSThread iOS Winding Rules