This article is a mirror article of machine translation, please click here to jump to the original article.

View: 241781|Reply: 55

[Console Program] .NET/C# uses FiddlerCore4 to intercept and modify HTTP requests

  [Copy link]
Posted on 12/20/2020 1:39:53 PM | | | |
The latest FiddlerCoreAPIFreeSetup, capture the new dll file, use it after installation, Fiddler's http custom interception processing library, FiddlerCore is currently available as a .NET class library, which can be used by any .NET application. FiddlerCore is designed for dedicated applications that run without a user interface, such as test automation, or UIs specifically for UIs that Fiddler Addon doesn't fit in, such as WPF traffic visualization.

FiddlerCore has now switched to paid, but before the charge, several new versions of .NET standard were released in beta, which were available and did not have a 30-day limit. The full SDK and demo are available. The download address is as follows:

FiddlerCoreAPIFree_4_6_20191_7809.zip download
The hyperlink login is visible.

Create a new .NET 4.6.2 console project: HttpCapture, which references the FiddlerCore45.dll class library, which can be obtained by downloading it as above.

The Fiddler event is as follows:

//
        Summary:
        //     This event fires when a session has been completed
        public static event SessionStateHandler AfterSessionComplete;
        //
        Summary:
        //     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;
        //
        Summary:
        //     This event fires when Response Headers are available
        public static event SessionStateHandler ResponseHeadersAvailable;
        //
        Summary:
        //     This event fires when Request Headers are available
        public static event SessionStateHandler RequestHeadersAvailable;
        //
        Summary:
        //     This event fires when a server response is received by Fiddler
        public static event SessionStateHandler BeforeResponse;
        //
        Summary:
        //     This event fires when a client request is received by Fiddler
        public static event SessionStateHandler BeforeRequest;
        //
        Summary:
        //     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;
        //
        Summary:
        //     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;
        //
        Summary:
        //     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;
        //
        Summary:
        //     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;
        //
        Summary:
        //     This event fires when an error response is generated by Fiddler
        public static event SessionStateHandler BeforeReturningError;
        //
        Summary:
        //     Fired each time Fiddler successfully accepts a TCP/IP connection
        public static event EventHandler<ConnectionEventArgs> AfterSocketAccept;
        //
        Summary:
        //     Fired each time Fiddler successfully establishes a TCP/IP connection
        public static event EventHandler<ConnectionEventArgs> AfterSocketConnect;

Commonly used events are BeforeRequest, BeforeResponse, and AfterSessionComplete.

If you want to block HTTPS requests, you need to install a certificate, the code is as follows:

Attached is the code to determine if the certificate exists:

The results we achieved were as follows:

1. Interceptwww.itsvse.comSite request, which returns a piece of JSON content directly.
2. Block the down.itsvse.com site, and after the response, replace the string "Uploaded by" with "Uploaded by"

The code is as follows:

Then set the ie agent 127.0.0.1:9099 manually, also with the code settings, as follows:

Set up the system IE proxy using .NET/C#
https://www.itsvse.com/thread-9495-1-1.html

The renderings are as follows:



Note: When modifying the content after the response, you need to set up a session in the BeforeRequest eventsession.bBufferResponse = true;, otherwise you can't modify the response content!

Source code download:

Tourists, if you want to see the hidden content of this post, pleaseReply


(End)





Previous:ASP.NET MVC online decompilation of the current website source code
Next:The request format is not recognized because the URL unexpectedly ends with "/itsvse".
 Landlord| Posted on 6/30/2023 8:07:39 PM |
About the certificate:

Posted on 3/6/2022 10:33:30 AM |
Very good                       
 Landlord| Posted on 6/28/2023 5:11:09 PM |
Resolved the issue that fiddler could not crawl local localhost, 127.0.0.1 network requests
https://www.itsvse.com/thread-9137-1-1.html
Posted on 12/23/2020 8:51:15 PM |
When modifying the content after the response
Posted on 2/25/2021 7:39:28 PM |

When modifying the content after the response
Posted on 3/1/2021 1:03:56 PM |
namespace of FiddlerCoreStartupSettingsBuilder
Posted on 3/13/2021 3:15:48 PM |
Learn the source code
Posted on 3/31/2021 5:15:20 PM |
Study it and take a look
Posted on 4/7/2021 6:09:31 PM |
After searching for a whole day, I finally found one that met my needs
Posted on 5/5/2021 4:28:11 PM |
Moving the ie proxy 127.0.0.1:9099 is also possible
Posted on 6/4/2021 11:27:23 AM |
333333333333333333
Posted on 6/21/2021 12:33:29 AM |
session.bBufferResponse = true; Is it necessary to set it?
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com