在 IHttpHandler 中访问原始 HTTP 请求数据包

发布于 2024-07-16 17:50:14 字数 688 浏览 5 评论 0原文

我正在尝试编写一个 IHttpHandler,它可以处理来自 Windows Media Player/Silverlight 的流媒体请求。 这意味着响应像这样的原始 HTTP 请求(取自协议文档)

"GET /ms/contoso_100_files/0MM0.wmv HTTP/1.0"
"Accept: */*"
"User-Agent: NSPlayer/4.1.0.3925"
"Host: netshow.micro.com"
"Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=0:0,request-context=1,max-duration=0"
"Pragma: xClientGUID={2200AD50-2C39-46c0-AE0A-2CA76D8C766D}"

当我进入 ProcessRequest 方法时, context.Request.Headers 集合似乎没有公开 Pragma 值。 此外,它永远无法真正做到这一点,因为有两行具有相同的键(Pragma)!

我假设如果我可以获得原始数据包,我可以手动解析它们。

也就是说,我接下来要做的就是构造一个 HttpWebRequest 类型的辅助请求。 它还包含一个类似的字典,我希望它也无法接受两个相同的 pragma 值,而不用一个覆盖另一个。

我错过了什么吗?

I am trying to write an IHttpHandler that can work with a request for streaming media coming from Windows Media Player/Silverlight. That means responding to a raw HTTP request like this (taken from the protocol document)

"GET /ms/contoso_100_files/0MM0.wmv HTTP/1.0"
"Accept: */*"
"User-Agent: NSPlayer/4.1.0.3925"
"Host: netshow.micro.com"
"Pragma: no-cache,rate=1.000000,stream-time=0,stream-offset=0:0,request-context=1,max-duration=0"
"Pragma: xClientGUID={2200AD50-2C39-46c0-AE0A-2CA76D8C766D}"

When I land in the ProcessRequest method, the context.Request.Headers collection does not seem to expose the Pragma values. Further, it can never really do it as there are two lines with the same key (Pragma)!

I am assuming that if I can get the original packet I could parse these out manually.

That said, the next thing I want to do with it is construct a secondary request of type HttpWebRequest. That also sports a similiar dictionary which I expect will also not be able to accept the two identical pragma values without one overwriting the other.

Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜深人未静 2024-07-23 17:50:15

事实上,没有 Pragma 标头让我认为它们可能不会被发送。 我建议您使用 Fiddler 来观察网络流量,以确保它们被发送给您。

The fact that there are no Pragma headers makes me think they might not be getting sent. I suggest you use Fiddler to watch the network traffic to make sure they're being sent to you.

深海蓝天 2024-07-23 17:50:15

您如何访问 Request.HeadersNameValueCollection 处理多个标头的情况,但您必须使用正确的成员来访问它们:(

string[] values = context.Request.GetValues("Pragma");

索引属性本质上执行 join(','...) 其中有多个值)。

How are you accessing Request.Headers? The NameValueCollection handles cases of multiple headers but you have to use the right members to access them:

string[] values = context.Request.GetValues("Pragma");

(The index property essentially performs a join(','...) where there are multiple values).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文