c# - 原始http请求解析
问题描述
我正在使用 windivert 来捕获 tcp 数据包。我成功捕获了 WinDivertSharp.dll 的数据包。现在我想解析只有http请求的数据包。要解析数据包,我正在使用流动代码。
var index = BinaryMatch(messageBody, Encoding.ASCII.GetBytes("\r\n\r\n")) + 4;
var headers = Encoding.ASCII.GetString(messageBody, 0, index);
var memory = new MemoryStream(messageBody);
memory.Position = index;
string body = "";
if (headers.IndexOf("Content-Encoding: gzip") > 0)
{
using (GZipStream decompressionStream = new GZipStream(memory, CompressionMode.Decompress))
using (var decompressedMemory = new MemoryStream())
{
decompressionStream.CopyTo(decompressedMemory);
decompressedMemory.Position = 0;
body = Encoding.UTF8.GetString(decompressedMemory.ToArray());
}
}
else
{
body = Encoding.UTF8.GetString(messageBody, index, messageBody.Length - index);
}
它适用于某些网站。但是对于来自https://stackoverflow.com/的 http 请求,它不起作用。请帮助解码各种网络的 http 请求。
解决方案
可能是一个长镜头,但它可能与WinDivert
不解密来自使用 SSL/TLS (HTTPS) 的站点的响应,例如https://stackoverflow.com/。
我建议您尝试比较使用 HTTP 和 HTTPS 的站点。
希望能帮助到你!
推荐阅读
- python - 从python中的父类实例化
- android - 如何使用 AppBarConfiguration 设置 NavigationView?
- sql - 如何根据另一个表值编写查询
- amazon-web-services - 将 npm db-migrate 与 Elastic Beanstalk 一起使用
- java - Hibernate - 重写旧版 createCriteria
- html - 鼠标悬停后隐藏嵌入的 youtube 视频控件
- reactjs - React Native Reanimated:如何将视图每帧移动 5 个像素?
- gitlab-ci - 在 GUI 上查看时,如何折叠部分 GitLab CI 作业日志?
- javascript - 使用 javascript 创建平滑的无限多项目轮播滑块
- windows - HAXM 未安装(Windows 10 家庭用户,Hyper-V 尚未安装)