charles

Charles is commonly used for network packet capture. Common uses are as follows:

  1. The development and debugging process is a great help in analyzing interface requests
  2. Tamper with the mock interface returns
  3. Local agent debug development
  4. Simulate slow conditions
  5. Do the pressure test
  6. Blocklist, which invalidates certain requests

Charles MacOS Enables Proxy Packet Capture (HTTP)

Go to the menu bar Proxy -> MacOS Proxy, remember to open to capture the local HTTP request, the principle is like this, Chares starts a Proxy server, all requests will pass through this Proxy server, you can go to the network Proxy Settings to check

Charles MacOS transfers HTTPS packets

The default HTTPS package will display the message “unknow Connect”. Click on the request and you will see the error message

SSLHandshakeException: Remote host closed connection during handshake
Copy the code

To Install the trust Certificate, go to Help -> SSL Proxy -> Install Charles Root Certificate

After the installation, the certificate setting page is displayed, and you need to trust the certificate. If the certificate cannot be found, Login to the certificate page, search for Charles, and always trust

Tips: There are some cases where HTTPS is still not available. You can try to decrypt the computer and install it again, or you can try to change the computer’s time to one day later

Charles skills

Simulate slow conditions

Menu bar Proxy -> Throttle Setting

Select Only for Selected hosts and then add the url. If you add the URL, you can leave it empty or * to check all the urls

Tamper with the mock interface returns

Right-click on the request and click Breakpoints to interrupt the request the next time it is requested, as shown below

There are three buttons,

  1. Abort, simulates a case where this interface does not return
  2. Execute, modify mock interface return, click to Edit Reques and Edit Response, here we Edit baidu HTML return title, add a test

Hit Execute again

Similarly, we can Edit Request and mock

There is also a place to manage all Breakpoints Settings. In Proxy -> Breakpoints Settings, you can add Breakpoints for any URL

Local agent debug development

For example, if we have some Local code and want to Map directly to the online website for debugging, we can use Map Remote and Map Local. And we can use the folder effect, can be corresponding to the two directories on the back of the tree structure of the file and folder can be corresponding to one.

blocklist

Sometimes we need to test the network for errors. This can be done using blocklist. To open the path, go to Tools -> Black List. The principle is to hijack the request, return 403 or simply discard the request

You can add rules that block only the specified URL

Import and Export in the lower left corner are Charles’ common URL path matching rules.

Pressure test

You can perform the repeat action on a request, right click to display the repeat and repeat Advanced actions, or go to Tools -> repeat and Tools > repeat Advanced.