When debugging Ajax requests, cross-origin issues are frequently encountered. One of the solutions to cross-origin problems is to add
Access-control-allow-origin: * Header
We need to use Fiddler to simulate this situation before the server is modified.
The two methods have their respective lengths. Let's talk about them first.
Method 1: Modify customrules. js
You can add a menu item to Fiddler by modifying customrules. js. The effect is permanently valid and easy to operate. You can also customize it at any time.
A. Add the following code to the public static rulesoption ("cache always & fresh", "per & formance") of customrules. JS:
JS Code
- // the newly added menu item
- rulesstring ("override & allow-origin", true) // level-1 menu name
- rulesstringvalue (1, "* .qq.com", "* .qq.com") // specify several default options
- rulesstringvalue (2, "* .tenpay.com", "* .tenpay.com")
- rulesstringvalue (3, "* .paipai.com", "* .paipai.com") // you can add it at any time.
- rulesstringvalue (4, "& custom...", "% custom %") // you can customize it. When you click it, the input is displayed.
- // if the value of the 4th parameter is true, the current rule is treated as the default rule and will take effect at each start, for example:
- // rulesstringvalue (5, "menu item display content", "corresponding value selected for menu item", true) // This option is selected by default.
- Public Static Var salloworigin: String = NULL; // define the variable name
B. Find the static function onbeforeresponse in customrules. js and add the following code to the function body:
Note: If you need cross-origin read/write cookies, you must set both access-control-allow-credentials: ture.
JS Code
- If (salloworigin ){
- Osession. oresponse ["access-control-allow-origin"] = salloworigin;
- Osession. oresponse ["access-control-allow-credentials"] = "true ";
- }
C. Save the customrules. js file. D. Remember to select the corresponding option under the Rules menu to take effect. Method 2: Use the built-in filter plug-in, as shown in figure
In the Add process, follow steps 1, 2, 3 to add
Use fiddler for cross-origin access