官方版

Create Fiddler Extension Project

Follow these steps to create a sample Fiddler Extension that modifies the User-Agent string of all outbound requests:

Add Reference to Fiddler

  1. Start Visual Studio 2005 or later.
  2. Create a new Project of type Visual C# Class Library.
  3. Right-click the project’s References folder in the Solution Explorer.
  4. Click the Browse tab and select Fiddler.exe in the C:\Program Files\Fiddler2 folder.
  5. Click Ok to add the reference.

    Add Reference to System.Windows.Forms

    If your extension modifies Fiddler’s UI:

  6. Right-click the project’s References folder in the Solution Explorer again.

  7. On the .NET tab, choose System.Windows.Forms.
  8. Click Ok to add the reference.

    Add Build Event

  9. In the Solution Explorer, right click the project.

  10. Click Properties.
  11. Click the Build Events tab.
  12. Add the following to the Post-build event command line:

    1. copy "$(TargetPath)" "%userprofile%\My Documents\Fiddler2\Scripts\$(TargetFilename)"

    Implement a Fiddler Interface

    Modify the default class1.cs (or create a new class) in your project as follows:

    1. using System;
    2. using System.Windows.Forms;
    3. using Fiddler;
    4. [assembly: Fiddler.RequiredVersion("2.3.5.0")]
    5. public class Violin : IAutoTamper // Ensure class is public, or Fiddler won't see it!
    6. {
    7. string sUserAgent = "";
    8. public Violin(){
    9. /* NOTE: It's possible that Fiddler UI isn't fully loaded yet, so don't add any UI in the constructor.
    10. But it's also possible that AutoTamper* methods are called before OnLoad (below), so be
    11. sure any needed data structures are initialized to safe values here in this constructor */
    12. sUserAgent = "Violin";
    13. }
    14. public void OnLoad(){ /* Load your UI here */ }
    15. public void OnBeforeUnload() { }
    16. public void AutoTamperRequestBefore(Session oSession){
    17. oSession.oRequest["User-Agent"] = sUserAgent;
    18. }
    19. public void AutoTamperRequestAfter(Session oSession){}
    20. public void AutoTamperResponseBefore(Session oSession){}
    21. public void AutoTamperResponseAfter(Session oSession){}
    22. public void OnBeforeReturningError(Session oSession){}
    23. }

    See Fiddler Interfaces.

    Compile and Load Extension

    Compile and Load Your Extension in Fiddler

谷歌翻译版

创建Fiddler扩展项目

请按照以下步骤创建一个示例Fiddler Extension,以修改所有出站请求的User-Agent字符串:

添加对Fiddler的引用

  1. 启动Visual Studio 2005或更高版本。
  2. 创建一个Visual c#类库类型的新项目。
  3. 解决方案资源管理器中右键单击项目的References文件夹。
  4. 单击Browse选项卡并选择Fiddler.exe C:\Program Files\Fiddler2文件夹。
  5. 单击Ok添加引用。

    添加对System.Windows.Forms的引用

    如果你的扩展修改了Fiddler的UI:

  6. 再次在解决方案资源管理器中右键单击项目的References文件夹

  7. .NET选项卡上,选择“ System.Windows.Forms”。
  8. 单击Ok添加引用。

    添加构建事件

  9. 在“解决方案资源管理器”中,右击项目。

  10. 单击属性
  11. 单击Build Events选项卡。
  12. 将以下内容添加到生成后事件命令行

    1. copy "$(TargetPath)" "%userprofile%\My Documents\Fiddler2\Scripts\$(TargetFilename)"

    实现一个Fiddler接口

    在项目中修改默认的class1.cs(或创建一个新类),如下所示

    1. using System;
    2. using System.Windows.Forms;
    3. using Fiddler;
    4. [assembly: Fiddler.RequiredVersion("2.3.5.0")]
    5. public class Violin : IAutoTamper // Ensure class is public, or Fiddler won't see it!
    6. {
    7. string sUserAgent = "";
    8. public Violin(){
    9. /* NOTE: It's possible that Fiddler UI isn't fully loaded yet, so don't add any UI in the constructor.
    10. But it's also possible that AutoTamper* methods are called before OnLoad (below), so be
    11. sure any needed data structures are initialized to safe values here in this constructor */
    12. sUserAgent = "Violin";
    13. }
    14. public void OnLoad(){ /* Load your UI here */ }
    15. public void OnBeforeUnload() { }
    16. public void AutoTamperRequestBefore(Session oSession){
    17. oSession.oRequest["User-Agent"] = sUserAgent;
    18. }
    19. public void AutoTamperRequestAfter(Session oSession){}
    20. public void AutoTamperResponseBefore(Session oSession){}
    21. public void AutoTamperResponseAfter(Session oSession){}
    22. public void OnBeforeReturningError(Session oSession){}
    23. }

    请参阅Fiddler接口

    编译并且加载扩展

    在Fiddler中编译并且加载扩展