|

最新的FiddlerCoreAPIFreeSetup,抓包新dll文件,安装后使用,Fiddler提供的http自定义拦截处理库,FiddlerCore目前作为.NET类库提供,可供任何.NET应用程序使用。FiddlerCore设计用于在没有用户界面(例如测试自动化)的情况下运行的专用应用程序,或者专门用于Fiddler Addon不适合的UI(例如WPF流量可视化)的UI。
FiddlerCore现在已经转为收费了,但在收费之前出过几个针对.net standard的新版本的测试版,这些版本是可以正常使用的,也没有30天的限制。完整的SDK和Demo都有。下载地址如下:
FiddlerCoreAPIFree_4_6_20191_7809.zip下载
超链接登录可见。
新建一个 .NET 4.6.2 的控制台项目:HttpCapture,引用 FiddlerCore45.dll 类库,可以通过如上下载获得。
Fiddler 事件如下:
//
// 摘要:
// This event fires when a session has been completed
public static event SessionStateHandler AfterSessionComplete;
//
// 摘要:
// This event fires when Fiddler captures a WebSocket message
public static event EventHandler<WebSocketMessageEventArgs> OnWebSocketMessage;
[CodeDescription("This event fires a HTTPS certificate is validated.")]
public static event EventHandler<ValidateServerCertificateEventArgs> OnValidateServerCertificate;
//
// 摘要:
// This event fires when Response Headers are available
public static event SessionStateHandler ResponseHeadersAvailable;
//
// 摘要:
// This event fires when Request Headers are available
public static event SessionStateHandler RequestHeadersAvailable;
//
// 摘要:
// This event fires when a server response is received by Fiddler
public static event SessionStateHandler BeforeResponse;
//
// 摘要:
// This event fires when a client request is received by Fiddler
public static event SessionStateHandler BeforeRequest;
//
// 摘要:
// This event fires each time FiddlerCore reads data from network for the client's
// request. Note that this data is not formatted in any way, and must be parsed
// by the recipient.
public static event EventHandler<RawReadEventArgs> OnReadRequestBuffer;
//
// 摘要:
// This event fires each time FiddlerCore reads data from network for the server's
// response. Note that this data is not formatted in any way, and must be parsed
// by the recipient.
public static event EventHandler<RawReadEventArgs> OnReadResponseBuffer;
[CodeDescription("This event fires when the user instructs Fiddler to clear the cache or cookies.")]
public static event EventHandler<CacheClearEventArgs> OnClearCache;
//
// 摘要:
// Sync this event to be notified when FiddlerCore has attached as the system proxy.")]
[CodeDescription("Sync this event to be notified when FiddlerCore has attached as the system proxy.")]
[Obsolete("Please, use the Telerik.NetworkConnections.NetworkConnectionsManager.")]
public static event SimpleEventHandler FiddlerAttach;
//
// 摘要:
// Sync this event to be notified when FiddlerCore has detached as the system proxy.
[CodeDescription("Sync this event to be notified when FiddlerCore has detached as the system proxy.")]
[Obsolete("Please, use the Telerik.NetworkConnections.NetworkConnectionsManager.")]
public static event SimpleEventHandler FiddlerDetach;
[CodeDescription("This event fires when a user notification would be shown. See CONFIG.QuietMode property.")]
public static event EventHandler<NotificationEventArgs> OnNotification;
//
// 摘要:
// This event fires when an error response is generated by Fiddler
public static event SessionStateHandler BeforeReturningError;
//
// 摘要:
// Fired each time Fiddler successfully accepts a TCP/IP connection
public static event EventHandler<ConnectionEventArgs> AfterSocketAccept;
//
// 摘要:
// Fired each time Fiddler successfully establishes a TCP/IP connection
public static event EventHandler<ConnectionEventArgs> AfterSocketConnect;
常用的就 BeforeRequest(请求之前)、BeforeResponse(响应之前)、AfterSessionComplete(请求会话完成) 事件。
如果想拦截 HTTPS 请求,需要安装证书,代码如下:
附上判断证书是否存在的代码:
我们实现的效果如下:
1.拦截 www.itsvse.com 站点请求,直接返回一段 json 内容。
2.拦截 down.itsvse.com 站点,在响应之后,替换字符串“上传者”为“Uploaded by(替换之后名称)”
代码如下:
然后手动设置 ie 代理 127.0.0.1:9099,也可以使用代码设置,如下:
效果图如下:
注意:在修改响应之后的内容的时候,需要在 BeforeRequest 事件设置会话 session.bBufferResponse = true; ,否则无法修改响应内容!
源码下载:
(完)
|
上一篇:ASP.NET MVC 在线反编译当前网站源码下一篇:因 URL 意外地以“/itsvse”结束,请求格式无法识别。
|