-->

How to use Charles' rewrite tool only on certa

2019-02-27 23:33发布

问题:

I'm using Charles' Rewrite Tool to change 200 responses to 400 in order to test failing API calls. However, the rewrite is triggering on the Options request. I'd like to only have it trigger on the Get or Post requests and allow the Options requests through. Is this possible using Charles?

回答1:

I think Charles does not have this option, which is really a pitty, because it seems to be easy to implement and it would open the doors to the API world.

I would suggest you to ask Karl (the author and main developer) for this new feature at the contact section of the site.



回答2:

We were able to work around the issue by assuming that OPTIONS would always return an empty body.

The below Regex values will match for GET (because it has a body) and not match for OPTIONS (because it doesn't have a body).

\{[\S\s]*\}

or

\[[\S\s]*\]



回答3:

We have this exact same need to mock API responses. Since the Rewrite tool doesn't support this feature, we have setup Breakpoints on the responses we want to mock, once the breakpoint is hit, we change the response to whatever we want. It works, but is less than ideal.