简体   繁体   English

如何从C#中的TCP数据包获取Http正文消息

[英]How to get Http Body Message From a TCP packet in C#

i'm working on a tcp listener project on c#. 我正在C#上的TCP侦听器项目上工作。 I'm using pcap.net for packet capture. 我正在使用pcap.net进行数据包捕获。 But when i'm trying to get the http message with such command like tcp.Http.Decode(Encoding.UTF8) , i get some encrypted script. 但是,当我尝试使用tcp.Http.Decode(Encoding.UTF8)这样的命令获取http消息时,我得到了一些加密的脚本。 I'm listening on sites that not using SSL protection. 我正在听未使用SSL保护的网站。 I tried tcp.Http.ToMemoryString() then decode it with UTF8 with bytes I can get the Http header properly but i cant get the HTTP message in a readable form. 我试过了tcp.Http.ToMemoryString()然后用字节的UTF8对其进行解码,我可以正确获取Http标头,但无法以可读形式获取HTTP消息。 Any ideas how can i do it or am i missing something? 任何想法我该怎么办还是我缺少什么?

You should use the HttpDatagram.Body property to get the body. 您应该使用HttpDatagram.Body属性获取正文。

This would return the parsed body part of the HTTP packet. 这将返回HTTP数据包的已解析主体部分。

Note though that you are parsing a single packet, so you will only get the data from that packet, which might not contain the entire HTTP response body. 请注意,尽管您正在解析单个数据包,所以您只会从该数据包中获取数据,而该数据包可能不包含整个HTTP响应主体。

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

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