Use fiddler for cross-origin access

Source: Internet
Author: User

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
    1. // the newly added menu item
    2. rulesstring ("override & allow-origin", true) // level-1 menu name
    3. rulesstringvalue (1, "* .qq.com", "* .qq.com") // specify several default options
    4. rulesstringvalue (2, "* .tenpay.com", "* .tenpay.com")
    5. rulesstringvalue (3, "* .paipai.com", "* .paipai.com") // you can add it at any time.
    6. rulesstringvalue (4, "& custom...", "% custom %") // you can customize it. When you click it, the input is displayed.
    7. // 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:
    8. // rulesstringvalue (5, "menu item display content", "corresponding value selected for menu item", true) // This option is selected by default.
    9. 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
    1. If (salloworigin ){
    2. Osession. oresponse ["access-control-allow-origin"] = salloworigin;
    3. Osession. oresponse ["access-control-allow-credentials"] = "true ";
    4. }
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.