I. Scene description

In daily development, when the development progress of the front and back ends is inconsistent or the development environment is limited, mock or packet capture is often used to intercept HTTP requests for interface testing after the front-end development is completed. Then, Fiddler is usually used for response interception and customized response according to the logical situation. However, cros can occur when using AutoResponse

Second, solutions

  • 1. Open the Fiddler client, locate and click Rules in the menu bar, and select Customize Rules to Customize interception Rules

  • 2. In the pop-up window, use Ctrl + F to open the search window and enter OnBeforeResponse to find the location as shown below

  • 3. In the OnBeforeResponse method, add the cross-domain request response header, as shown below, and save it by Ctrl + S (note that the box position in the figure is the corresponding server domain name, please change it according to the actual domain name).
if(oSession.uriContains("test.test.com")){
    oSession.oResponse["Access-Control-Allow-Origin"] =  "*";
    oSession.oResponse["Access-Control-Allow-Credentials"] = true;
    oSession.oResponse["Access-Control-Allow-Headers"] = "accept, content-type, x-requested-with";
}
Copy the code

  • 4, add rule selection response file in AutoResponse, open the rule can be happy to intercept the request

Finally, if it is helpful to you, please give me a thumbs-up. Your thumbs-up is my motivation to continue sharing. Thank you!!