C# 捕获 HTTP 请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/532746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 07:05:07  来源:igfitidea点击:

Capturing HTTP requests

c#http

提问by Robert Morgan

Is there a way to monitor and capture all outgoing HTTP requests from a machine using C#?

有没有办法使用 C# 监视和捕获来自机器的所有传出 HTTP 请求?

I need a browser independent way of logging visited URLs.

我需要一种独立于浏览器的方式来记录访问过的 URL。

采纳答案by WiseTechi

You may want to use existing network interfaces capturing libraries like pcap or winpcap to do so. Rewriting all the necessary stuff by yourself would be quite time expensive.

您可能希望使用现有的网络接口捕获库(如 pcap 或 winpcap)来执行此操作。自己重写所有必要的东西会很费时间。

Link to Pcap

链接到Pcap

Link to WinPcap

链接到WinPcap

Edit : Just saw someone also wrote the C# bindings to winpcap : SharpPcap

编辑:刚刚看到有人还写了 C# 绑定到winpcapSharpPcap

回答by Rob

I use fiddler ( http://www.fiddler2.com)

我使用提琴手(http://www.fiddler2.com

回答by ZombieSheep

You're probably going to save lots of time and effort with some kind of proxy setup. A decent local-machine solution would be Fiddler(requires Windows), or something like a Squidserver for a networked solution.

通过某种代理设置,您可能会节省大量时间和精力。一个不错的本地机器解决方案是Fiddler(需要 Windows),或者像Squid服务器这样的网络解决方案。

回答by CraigTP

Sounds like you're after some kind of "packet sniffing" utility.

听起来您正在使用某种“数据包嗅探”实用程序。

Here's a couple of links to articles on the Code Project site for packet sniffers (with downloadable source code) written in C#:

以下是 Code Project 站点上关于用 C# 编写的数据包嗅探器(带有可下载的源代码)的文章的几个链接:

Packet Capture and Analayzer

数据包捕获和分析器

A Network Sniffer in C#

C#中的网络嗅探器

If you're just after capturing visited URL's, these utilities may be overkill, however, you'll be able to extract a URL from your HTTP packets and discard the rest, however, you may also wish to capture all packet information, in which case, these utilities will help.

如果您只是在捕获访问过的 URL 之后,这些实用程序可能有点过头了,但是,您可以从 HTTP 数据包中提取一个 URL 并丢弃其余部分,但是,您可能还希望捕获所有数据包信息,其中在这种情况下,这些实用程序会有所帮助。

回答by Vasil

Also, writing a simple http proxy for this purpose in C# is a trivial task.

此外,为此在 C# 中编写一个简单的 http 代理是一项微不足道的任务。

回答by Ahmed Atia

I hope if Wireharkworks for you. It's free and cross-platform. Also, "Wireshark is the world's foremost network protocol analyzer, and is the de facto (and often de jure) standard across many industries and educational institutions"

我希望Wirehark对你有用。它是免费且跨平台的。此外,“Wireshark 是世界上最重要的网络协议分析器,并且是许多行业和教育机构的事实上(并且通常是法律上的)标准”

Have look, Wireshark-Wikipedia

看看, Wireshark-维基百科