简体   繁体   English

如何拦截来自应用程序的HTTP调用?

[英]How to intercept HTTP calls from an application?

I want to watch all the HTTP requests going out of a certain application and cancel them if needed. 我想观看从某个应用程序发出的所有HTTP请求,并在需要时取消它们。

Is there a way to do this in C#? 有没有办法在C#中做到这一点?

If you can touch the system's proxy configuration (which is used by many applications) or, if the app doesn't heed that setting, touch the application's configuration to use a proxy of your choice, you can create a HTTP proxy that would do the job for you. 如果您可以触摸系统的代理配置(许多应用程序使用它),或者如果应用程序没有注意到该设置,请触摸应用程序的配置以使用您选择的代理,您可以创建一个HTTP代理来执行为你工作。

If you just want to profile, there is a ready made tool that behaves like this and is very nice, Fiddler . 如果你只是想描述一下,有一个现成的工具,表现得像这样,非常好, Fiddler

Else you'd have to go deeper into the network stack and implement something like a sniffer/firewall, for instance using WinPcap . 否则,您必须深入了解网络堆栈并实现类似嗅探器/防火墙的功能,例如使用WinPcap That's a lot harder to do. 这样做要困难得多。

If you're working with Windows, it is possible to hook the WinInet API calls and do whatever you want with them. 如果您正在使用Windows,则可以挂钩WinInet API调用并随意执行任何操作。

FreeCap (or its commercial version, WideCap) does that: allows you to send TCP traffic through a proxy server. FreeCap (或其商业版本,WideCap)可以:允许您通过代理服务器发送TCP流量。 That proxy might then do the filtering (eg Fiddler ). 然后该代理可以进行过滤(例如Fiddler )。

I know this brings more stand-alone applications into the system, but it works. 我知道这会为系统带来更多的独立应用程序,但它确实有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM