Logo for tanaschita.com

Manipulating networking requests and responses with Charles

Learn how to use Charles breakpoints tool to change network data and test your iOS application.

07 Mar 2022 · 4 min read

Charles is a proxy server that enables us to view the networking traffic between the app and the internet.

In Quick guide on Charles Proxy for iOS development, we already looked at the features Charles has to offer and how to use them.

In this article, we are going to dive more deeper and look at the Charles breakpoints tool. It lets us intercept and manipulate requests and responses before they are passed through Charles.

Being able to manipulate response data is a great way to test how the app handles unexpected values. Let's get started.

Setting up a breakpoint

Each breakpoint in Charles matches a URL using location matching patterns and is also assigned to either the request, the response or both.

The simplest way to enable a breakpoint is by selecting the URL and then clicking the breakpoint button in the top toolbar.

Enable breakpoints.
Enable breakpoints.

For more control, open Proxy -> Breakpoint Settings in the menu. Here, we see an overview of all the breakpoints that are set, can edit, remove them or add new ones.

Breakpoint settings.
Breakpoint settings.

When editing or adding a breakpoint, we are able to configure details like protocol, host, port, path patterns or wildcards. Here, we can also select whether the breakpoint should be assigned to the request, the response or both.

Editing request and response data

When a request hits a breakpoint, the breakpoints window automatically opens in Charles we can view and edit the data.

Edit request in Charles.
Edit request.

The same happens when a response hits a breakpoint.

Edit response.
Edit response.

After editing, we can use different action buttons on how Charles should proceed with the request or response. The following actions are available:

  • Execute: Applies any changes we made and lets the request or response proceed.
  • Abort: Blocks the request or response and sends an error message to the client.
  • Cancel: Discards any changes we made and lets the request or response proceed as originally received.

Conclusion

Charles breakpoint tool is an easy to use and powerful way to debug our applications.

Charles offers even more advanced tools like repeating, automatic rewrites, map local, map remote, cache, cookies control and more. Check out their official tools documentation to check those out.

Newsletter

Receive a monthly newsletter about the latest articles and tips.

Image of a reading marmot

Related tags

Written by

Articles with related topics

Latest articles and tips