On the Charles menu bar, choose "Proxy"-> "Recording Settings", select the Include column, select Add a project, and enter the protocol, host address, and port number to be monitored. In this way, only the packets of the target website can be intercepted. As shown in:
In general, we use method 1 for some temporary packet filtering, and method 2 for some regular packet filtering.
Intercept Network packets on the iPhoneCharles is usually used to intercept local network packets, but we can also intercept network requests from other devices when necessary. Next I will take the iPhone as an example to explain how to perform the corresponding operations.
Settings on CharlesTo intercept network requests on the iPhone, we must first enable Charles's proxy function. On the Charles menu bar, select "Proxy"-> "Proxy Settings", fill in the Proxy port 8888, and check "Enable transparent HTTP proxying" to complete the Settings on Charles. As shown in:
Settings on iPhoneFirst, we need to obtain the IP address of the computer where Charles runs, open Terminal, and enterifconfig en0
To obtain the IP address of the computer, as shown in:
On the iPhone's "Settings"> "Wireless LAN", you can see the wifi name of the current connection. Click the details key on the right to view the details of the wifi on the current connection, includes IP addresses, subnet masks, and other information. There is an "HTTP proxy" item at the bottom. We will switch it to manual, and then fill in the IP address of the computer where Charles runs, and the port number 8888, as shown in:
After the settings are complete, open any program on the iPhone that requires network communication, and you will see Charles pop-up confirmation menu for iPhone request connection (as shown in). Click "Allow" to complete the settings.
Intercept SSL informationCharles does not intercept SSL information by default. If you want to intercept all SSL network requests on a website, right-click the request and select SSL proxy, as shown in:
In this way, all SSL requests to the Host can be intercepted.
Simulate slow networkDuring iPhone development, we often need to simulate a slow network or a high-latency network to test whether the application works normally on a mobile network. Charles provides good support for this demand.
On the Charles menu, select "Proxy"-> "Throttle Setting". In the displayed dialog box, select "Enable Throttling ", you can also set the Throttle Preset type. As shown in:
If you Only want to simulate the slow network of the specified website, you can check the "Only for selected hosts" option and add the specified hosts item in the lower half of the dialog box.
Modify network request contentSometimes, to debug server interfaces, We need to repeatedly try network requests with different parameters. Charles can easily modify and resend network requests. You can create an editable network request by right-clicking previous network requests and selecting "Edit. As follows:
You can modify any information about the request, including the url, port, and parameters. Then, click "Execute" to send the modified network request, as shown in ). Charles allows us to modify and send this request multiple times, which is very convenient for us and the server-side debugging interface.
SummaryWith the Charles software, we can easily intercept and debug network request content in daily development, analyze the packet protocol and simulate a slow network. Using Charles can greatly facilitate the development and debugging of apps with network requests.