HttpListener和“接受范围" [英] HttpListener and "Accept-Ranges"

查看:89
本文介绍了HttpListener和“接受范围"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的httpListener有一个异常问题(我认为)

我已经编写了UPnP媒体服务器并对其功能进行了扩展,我编写了UPnP中继,它将主要服务扩展到其他远程网络(它基本上只是将请求代理回主服务器,以欺骗客户端)充实其本地托管的内容)

有了音频,它的效果很好,但视频只是拒绝播放,我终于找到了原因

看一下这两组标题,一组是本地网络看到的,另一组是Remote

本地连接:

Hi All,

I have an unusual problem with httpListener (i think)

I''ve written a UPnP Media server and to extend it''s capabilities i''ve written UPnP Relays that extend the primary service to other remote networks (it basically just proxies the requests back to the main server, to fool the client into bellieving its locally hosted content)

With audio it works beautifully, but video simply refused to stream, i''ve finally found the reason

Look at these 2 sets of headers, One is what the local network see''s, the other is Remote

Local connections:

TransferMode.DLNA.ORG: Streaming
Accept-Ranges: bytes
Content-Length: 700631040
Content-Type: video/x-msvideo
Date: Wed, 28 Nov 2012 16:43:55 GMT
Server: Microsoft-HTTPAPI/2.0



远程连接:



Remote Connections:

TransferMode.DLNA.ORG: Streaming
Accept-Ranges: none
Content-Length: 700631040
Content-Type: video/x-msvideo
Date: Wed, 28 Nov 2012 16:44:58 GMT
Server: Microsoft-HTTPAPI/2.0



如您所见,Accept-Ranges标头已被某些内容更改,我无法弄清正在更改的内容以及原因

如果有人可以确认它是HttpListener类的限制,那么我将编写自己的http服务器类,但是为什么在不必时重新发明轮子呢?

作为参考,下面是发出请求的代码(仅收集标头)



As you can see, the Accept-Ranges header is being changed by something and i cant figure out what''s changing it and why

If somebody can confirm that its a limitation of the HttpListener Class then i''ll write my own http server class, but why reinvent the wheel when you dont have to?

For reference, heres the code making the requests (only gathers the headers)

Dim req As HttpWebRequest = HttpWebRequest.Create(url)
Dim res = req.GetResponse
For Each h As String In res.Headers
    Console.WriteLine(h & ": " & res.Headers(h))
Next



所有建议/帮助表示赞赏:-)

克里斯



All Advice/Help appreciated :-)

Chris

推荐答案

根据您的内容长度,我假设您在每种情况下都获得相同的数据,建议您对它们进行类似的解码.我也在网上找到了它:-

Based on your content length I assume that you are gettin the same data in each case, I suggest you decode them similarly. I also found this on line :-

报价:

14.5接受范围
接受范围响应标头字段允许服务器
表示接受资源范围请求:
Accept-Ranges ="Accept-Ranges":"可接受范围
可接受范围= 1#范围单位| 无"
接受字节范围请求的原始服务器可以发送
接受范围:字节
但并非必须这样做.客户端可以生成字节范围
请求但未收到资源的此标头
涉及.范围单位在第3.12节中定义.
不接受任何范围请求的服务器
资源可以发送
接受范围:无
劝告客户不要尝试进行范围请求.

14.5 Accept-Ranges
The Accept-Ranges response-header field allows the server to
indicate its acceptance of range requests for a resource:
Accept-Ranges = "Accept-Ranges" ":" acceptable-ranges
acceptable-ranges = 1#range-unit | "none"
Origin servers that accept byte-range requests MAY send
Accept-Ranges: bytes
but are not required to do so. Clients MAY generate byte-range
requests without having received this header for the resource
involved. Range units are defined in section 3.12.
Servers that do not accept any kind of range request for a
resource MAY send
Accept-Ranges: none
to advise the client not to attempt a range request.



http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html [ ^ ]

您可以查看另一个选项,即Service Point Manager回叫,将其放置在代码中并通过它进行调试

http://msdn.microsoft.com/en-us/library/system. net.security.remotecertificatevalidationcallback.aspx [ ^ ]

如果您在服务器信任方面遇到错误,则可以将回调设置为返回true以信任所有远程服务器



http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html[^]

There is another option that you can look at, Service Point Manager Call Back, place this in your code and debug through it

http://msdn.microsoft.com/en-us/library/system.net.security.remotecertificatevalidationcallback.aspx[^]

if you are getting an error on the server trust then you can set the call back to return true to trust all remote servers


您好,感谢您的答复,

是的,在每种情况下都将发送相同的数据,但是由于这是流服务器,因此"Accept-Ranges"标头对于允许进行avi流传输至关重要.

关于报价,我不太确定其相关性,在这两种情况下,我的服务器均响应完全相同的请求,只是一个来自局域网,一个来自远程网络. >
我需要确定正在更改"Accept-Ranges"标头,"HttpListener"或两者之间的其他内容的

我还想提到我的防火墙是一个音墙(以防万一它是相关的,我不认为是)

如果它是HttpListener,那么它很简单,我会写我自己的,但是如果我不必(我知道我很懒惰)(我知道)
Hi, thanks for the reply,

Yes the same data is being sent in each case but as this is a stream server the "Accept-Ranges" header is crucial to allow avi streaming

In respect of the quote, i''m not really sure where its relevant, in both cases its the same server responding to exactly the same request, just that one is from a local area network and one is from a remote network

I need to determine what is changing the "Accept-Ranges" header, The "HttpListener" or something else inbetween

I also want to mention that my firewall is a sonicwall (just in case it''s relevant, i dont think it is though)

If its the HttpListener then its simple, i''ll write my own, but dont want to do it if i dont have to (yeah lazy i know)


您可能会去那里的某事:-)

刚刚写了一个非常基本的http服务器,得到了完全相同的结果,即使尝试接受范围:香蕉",它仍然更改为接受范围:无",所以我认为您可能是正确的,我会进行测试并向后报告
You may be on to something there :-)

Just wrote a very basic http server and got exactly the same result, Even when trying "Accept-Ranges: bananas" it still got changed to "Accept-Ranges: none", so i think you may be correct, i''ll test and report back


这篇关于HttpListener和“接受范围"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆