官方版

Extend Fiddler with .NET Code

Use Fiddler’s extensibility mechanisms to add to Fiddler’s UI, automatically modify requests or responses, and create custom Inspectors that enable scenario-specific display and manual-modification of requests and responses.

Requirements

  • Visual Studio .NET 2005+ or the free .NET Framework v2 command-line compilers
  • The most recent version of Fiddler
  • For Visual Studio 2010 or later: Change the project to target the .NET2.0/3.5 framework.
  • If targeting .NET Framework 3.5: Ensure user has .NET Framework 3.5 installed.
  • If extending 64bit Fiddler: Target AnyCPU.

See Build extension assemblies to run in both Fiddler 2 and 4.

Debugging

  • To ensure that exceptions and other extension-related errors are not silently caught: set the fiddler.debug.extensions.showerrors preference to True.
  • To output logging information to the Log tab: set the fiddler.debug.extensions.verbose

    Direct Fiddler to load extension assemblies

  • To make the extensions available to all users on the machine, install extension assembly DLLs to:

    1. %Program Files%\Fiddler2\Scripts
  • To make the extensions available to only the current user, install extension assembly DLLs to:

    1. %USERPROFILE%\My Documents\Fiddler2\Scripts
  • Set the Fiddler.RequiredVersion attribute in your AssemblyInfo.cs file (or elsewhere in your code) as follows: ```vbnet using Fiddler;

// Extension requires Fiddler 2.2.8.6+ because it uses types introduced in v2.2.8… [assembly: Fiddler.RequiredVersion(“2.2.8.6”)]

  1. <a name="sample-extension-step-by-step"></a>
  2. ## [Sample Extension: Step by Step](https://docs.telerik.com/fiddler/Extend-Fiddler/ExtendWithDotNet#sample-extension-step-by-step)
  3. 1. Start **Visual Studio 2005** or later.<br />
  4. 1. Create a new Project of type **Visual C# Class Library**.<br />
  5. 1. Right-click the project's **References** folder in the **Solution Explorer**.<br />
  6. 1. Click the **Browse** tab and select **Fiddler.exe** in the **C:\Program Files\Fiddler2** folder.<br />
  7. 1. Click **Ok** to add the reference.<br />
  8. 1. If your extension modifies Fiddler's UI:
  9. - Right-click the project's References folder in the Solution Explorer again
  10. - On the .NET tab, choose System.Windows.Forms.
  11. - Click Ok to add the reference.
  12. - In the Solution Explorer, right click the project. Choose Properties.
  13. - On the Build Events tab, add the following to the Post-build event command line:<br />copy "$(TargetPath)" "%userprofile%\My Documents\Fiddler2\Scripts\$(TargetFilename)"<br />
  14. Modify the default class1.cs (or create a new class) in your project as follows:<br />
  15. ```vbnet
  16. using System;
  17. using System.Windows.Forms;
  18. using Fiddler;
  19. [assembly: Fiddler.RequiredVersion("2.3.5.0")]
  20. public class Violin : IAutoTamper // Ensure class is public, or Fiddler won't see it!
  21. {
  22. string sUserAgent = "";
  23. public Violin(){
  24. /* NOTE: It's possible that Fiddler UI isn't fully loaded yet, so don't add any UI in the constructor.
  25. But it's also possible that AutoTamper* methods are called before OnLoad (below), so be
  26. sure any needed data structures are initialized to safe values here in this constructor */
  27. sUserAgent = "Violin";
  28. }
  29. public void OnLoad(){ /* Load your UI here */ }
  30. public void OnBeforeUnload() { }
  31. public void AutoTamperRequestBefore(Session oSession){
  32. oSession.oRequest["User-Agent"] = sUserAgent;
  33. }
  34. public void AutoTamperRequestAfter(Session oSession){}
  35. public void AutoTamperResponseBefore(Session oSession){}
  36. public void AutoTamperResponseAfter(Session oSession){}
  37. public void OnBeforeReturningError(Session oSession){}
  38. }

谷歌翻译版

.NET代码扩展Fiddler

使用Fiddler的可扩展性机制添加到Fiddler的UI, 自动修改请求或响应, 或者创建自定义检查器,以启用特定于场景的显示和手动修改请求和响应。

要求

  • Visual Studio .NET 2005+或免费的.NET Framework v2命令行编译器
  • 最新版本的 Fiddler
  • 对于Visual Studio 2010或更高版本:将项目更改为以.NET2.0 / 3.5框架为目标。
  • 如果以.NET Framework 3.5为目标:确保用户已安装.NET Framework 3.5
  • 如果扩展64位Fiddler:目标AnyCPU

请参阅构建扩展程序集以在Fiddler2和4中运行

调试

  • 为确保不会默默捕获异常和其他与扩展相关的错误:请设置fiddler.debug.extensions.showerrors首选项为True。
  • 要将日志记录信息输出到Log选项卡:设置 fiddler.debug.extensions.verbose

    直接将Fiddler加载到扩展程序集

  • 要使扩展可供计算机上的所有用户使用,请将扩展程序集DLL安装到:

    1. %Program Files%\Fiddler2\Scripts
  • 若要使扩展仅对当前用户可用,请将扩展程序集DLL安装到:

    1. %USERPROFILE%\My Documents\Fiddler2\Scripts
  • 在您的AssemblyInfo.cs文件(或代码中的其他位置)中设置Fiddler.RequiredVersion属性,如下所示: ```vbnet using Fiddler;

// Extension requires Fiddler 2.2.8.6+ because it uses types introduced in v2.2.8… [assembly: Fiddler.RequiredVersion(“2.2.8.6”)]

  1. <a name="ztwPA"></a>
  2. ## [示列扩展程序: 一步一步](https://docs.telerik.com/fiddler/Extend-Fiddler/ExtendWithDotNet#sample-extension-step-by-step)
  3. 1. 启动**Visual Studio 2005**或更高版本。
  4. 1. 创建类型为**Visual C#类库**的新项目。
  5. 1. 在**解决方案资源管理器**中右键单击项目的**References**文件夹。
  6. 1. 单击**Browse**选项卡,然后在**C:\Program Files\Fiddler2**文件夹中选择**Fiddler.exe**。
  7. 1. 单击Ok添加引用。
  8. 1. 如果您的扩展程序修改了Fiddler的UI:
  9. - 再次在解决方案资源管理器中右键单击项目的References文件夹
  10. - 在**.NET选项卡**上,选择“ System.Windows.Forms”。
  11. - 单击Ok添加引用。
  12. - 在“解决方案资源管理器”中,右击项目。选择属性。
  13. - 在Build Events选项卡上,将以下内容添加到Build后事件命令行<br />copy "$(TargetPath)" "%userprofile%\My Documents\Fiddler2\Scripts\$(TargetFilename)"
  14. 在项目中修改默认的class1.cs(或创建一个新类),如下所示:
  15. ```vbnet
  16. using System;
  17. using System.Windows.Forms;
  18. using Fiddler;
  19. [assembly: Fiddler.RequiredVersion("2.3.5.0")]
  20. public class Violin : IAutoTamper // Ensure class is public, or Fiddler won't see it!
  21. {
  22. string sUserAgent = "";
  23. public Violin(){
  24. /* NOTE: It's possible that Fiddler UI isn't fully loaded yet, so don't add any UI in the constructor.
  25. But it's also possible that AutoTamper* methods are called before OnLoad (below), so be
  26. sure any needed data structures are initialized to safe values here in this constructor */
  27. sUserAgent = "Violin";
  28. }
  29. public void OnLoad(){ /* Load your UI here */ }
  30. public void OnBeforeUnload() { }
  31. public void AutoTamperRequestBefore(Session oSession){
  32. oSession.oRequest["User-Agent"] = sUserAgent;
  33. }
  34. public void AutoTamperRequestAfter(Session oSession){}
  35. public void AutoTamperResponseBefore(Session oSession){}
  36. public void AutoTamperResponseAfter(Session oSession){}
  37. public void OnBeforeReturningError(Session oSession){}
  38. }