Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify HTTP response body with Charles Proxy rewrite tool and regex?

I'm trying to change HTTP response body with Charles Proxy using rewrite tool / regex? The response is a JSON.

So part of the returned response JSON body is:

"unavailablePosts": ["AA", "BB"],

and what I want is:

"unavailablePosts": "XXX",

I try to set up Charles' rewrite like this:

enter image description here

So the regex is like:

"unavailablePosts": \[(.*)\],

But ... (as I'm asking this question) it does not work, i.e. nothing is changed in response body.

like image 555
Marian Paździoch Avatar asked Nov 04 '16 10:11

Marian Paździoch


People also ask

How do you edit a response in Charles proxy?

Charles Proxy change responseMap Local Tool ⌘ command + ⌥ option + L - Use local files to serve remote location. Map Remote Tool ⌘ command + ⌥ option + M - Modify the request location to map one remote location to another. Rewrite Tool ⌘ command + ⌥option + R - Modify requests and responses as they pass through ...


1 Answers

I believe there are some linebreaks in between the values, and to match them you need to add \s* (zero or more whitespaces) around : and use [\s\S]*? (any 0+ chars but as few as possible as *? is a lazy quantifier) to match the substring between [ and ],:

 "unavailablePosts"\s*:\s*\[([\s\S]*?)\],
like image 190
Wiktor Stribiżew Avatar answered Sep 22 '22 08:09

Wiktor Stribiżew