As a prerequisite to the below, ensure the SSL proxying settings and certificates are set and Charles is logging requests from the browser you're targeting.
Map Local
You can define modified response bodies to be loaded instead of the actual responses.
First, ensure the following rewrite rule is in place for CORS:
- Under Tools, select Rewrite...
- Ensure the Enable Rewrite checkbox is checked
- Add a new rule
- Add the relevant URIs (you can use an asterisk as a wildcard)
- Add the actual rule
Type: Modify Header
Where: Response
Name: X-Charles-Map-Local
Replace:
Name: Access-Control-Allow-Origin
Value: * - Ensure the rule is checked
- Apply it
- Reload the page with the request you're targeting
Then create the modified response to map to:
- In a browser, open up the developer console's Network tab
- In the browser, trigger the response you want to modify
- Copy the response
- Paste the response into an editor which parses it nicely
- Modify the response to whatever you would like to see (whilst remaining valid)
Then map to it:
- Under Tools, select Map Local...
- Ensure the Enable Map Local checkbox is checked
- Add a new mapping
- Add the relevant URIs (you can copy the URI from the browser request and paste it in the Host field, Charles will break the URI into the appropriate fields once you move focus away from the Host field)
- Choose the local response file to map to
- Save the mapping
- Ensure the mapping is checked (and that potentially conflicting mappings are not checked)
- Reload the page with the request you're targeting
Rewrite
You can enable or disable rewrites of request/response bodies, parameters, or status codes to be in place whenever you use the targeted URI(s).
- Under Tools, select Rewrite...
- Ensure the Enable Rewrite checkbox is checked
- Add a new rule
- Add the relevant URIs (you can copy the URI from the browser request and paste it in the Host field, Charles will break the URI into the appropriate fields once you move focus away from the Host field)
- Add the actual rule
- Ensure the rule is checked (and that potentially conflicting rules are not checked)
- Apply it
- Reload the page with the request you're targeting
Example rules:
Type: Response Status
Where: Response (automatic)
Match - Value: 200
Replace - Value: 500
Type: Body
Where: Response
Match - Value: "Expires":"2018-07-31T14:44:44Z"
Replace - Value: "Expires":"2018-07-31T14:49:44Z"
Type: Body
Where: Request & Response
Match - Value: Details
Replace - Value:
Type: URL
Where: Request (automatic)
Match - Value: register
Replace - Value: asdf
Type: Modify Query Param
Where: Request (automatic)
Match - Name: LanguageCode
Match - Value: en
Replace - Name: LanguageCode
Match - Value: jp
Breakpoints
You can target requests 'live' where Charles will interrupt further requests and allow you to edit its parameters and continue with the changed parameters.
- Under Proxy (or from the toolbar), select Enable Breakpoints
- Under Proxy, select Breakpoint Settings...
- Add a new breakpoint
- Select whether you want to target a GET or POST request in the Scheme field
- Add the relevant URIs (you can copy the URI from the browser request and paste it in the Host field, Charles will break the URI into the appropriate fields once you move focus away from the Host field)
- Select whether you want to target the request and/or the response
- Ensure the breakpoint is checked (and that potentially conflicting breakpoints are not checked)
- Trigger the request in the browser
- Edit the parameters as desired
- Execute the amended request/response
- Return to the browser