The basic usage of charles will not be repeated. This article mainly summarizes several ways to modify requests and responses.
The test request used in this article is the local interface: http://sunset.com:8000/file/avatar/goods-001.jpg?name=test&age=20
-
Modify the request message through compose, which is similar to postman's simulated request
Select the request intercepted by charles, right click –>compose
As shown in the figure: Label 1 can see the parameters of this request, which can be modified here; Label 2 can add and delete query parameters; Label 3 executes the modified request;
-
Modify the request and response through rewrite
Click the menu tools–>rewrite to open the Rewrite Setting window
Then we test the request in the browser
The test only modifies the response body data, and this rewrite can also modify other types of data such as the response status code. -
Rewrite the response by mapping local files
Select the request intercepted by charles, right click and select save response, which can be saved in .json format
Open the file you just saved and modify the data inside
Right-click the request again, select map local, and open the configuration window
Then open the test in the browser, you can see the content we just modified.
-
Modify requests and responses through breakpoints
Select the request intercepted by charles, right click and select breakpoints
Then use the browser to initiate the request again
After clicking execute, you can see the breakpoint and go to the response editor
After performing the operation, you can see that the response on the browser side has changed
Finish