如何prevent分组分片对的HttpWebRequest分片、prevent、HttpWebRequest

2023-09-03 05:02:41 作者:骑着蜗牛看世界

我有一个嵌入式设备上使用的HttpWebRequest针对HTTP守护进程的一个问题。这个问题似乎是,有足够的HTTP标头之间的延迟被写入套接字流,和HTTP有效负载(POST),该插座释放什么,在套接字缓冲区到服务器。此结果在HTTP请求被分割到两个包(碎片)。

I am having a problem using HttpWebRequest against a HTTP daemon on an embedded device. The problem appears to be that there is enough of a delay between the http headers being written to the socket stream, and the http payload (a POST), that the socket releases what's in the socket buffer to the server. This results in the HTTP request being split over two packets (fragmentation).

这是完全有效的,当然,但是该服务器的另一端不应付它,如果分组超过约为1.8ms拆分。所以,我想知道是否有任何实际的方式来控制(客户端)。

This is perfectly valid, of course, however the server the other end doesn't cope with it if the packets are split by more than about 1.8ms. So I am wondering if there are any realistic ways to control this (on the client).

似乎没有要对HttpWebRequest的里让用于发送插座此控制级别任何属性,和一种不能出现访问套接字本身(即通过反射),因为它仅在所创建的送,事后发布(作为出站HTTP连接池的东西的一部分)。该BufferWriteStream酒店仅有缓存内的WebRequest的主体内容(所以它仍然可以重定向等),并没有出现影响总体要求写入到插座的方式。

There do not appear to be any properties on HttpWebRequest that give this level of control over the socket used for the send, and one can't appear to access the socket itself (ie via reflection) because it is only created during the send, and released afterwards (as part of the outbound http connection pooling stuff). The BufferWriteStream property just buffers the body content within the webrequest (so it's still available for redirects etc...), and doesn't appear to affect the way the overall request is written to the socket.

那么怎么办?

(我真的想避免从插座了重新编写的HTTP客户端)

(I'm really trying to avoid having to re-write the HTTP client from the socket up)

一个选择可能是写一些类型的代理,该HttpWebRequest的发送到(通过的ServicePoint也许),并且在实施缓冲整个TCP请求。但是,这似乎是一个大量艰苦的工作。

One option might be to write some kind of proxy that the HttpWebRequest sends to (maybe via the ServicePoint), and in that implementation buffer the entire TCP request. But that seems like a lot of hard work.

这也是当我跑Fidder(出于同样的原因),工作正常,但是这不是真的在我们的生产环境中的一个选项...

It also works fine when I'm running Fidder (for the same reason) but that's not really an option in our production environment...

[PS:我知道这是肯定的分片报文这就是问题之间的间隔,因为我敲了一个套接字级的试验中,我明确地控制了碎裂使用无需等待的插座]

[ps: I know it's definately the interval between the fragmented packets that's the problem, because I knocked up a socket-level test where I explicitly controlled the fragmentation using a NoDelay socket]

推荐答案

在年底厂商推出,其中包括HTTPD的新版本固件升级和问题走了。他们使用了BusyBox的Linux,显然还有一些其他的问题在httpd的实现,他们已经遭受了。

In the end the vendor pushed out a firmware upgrade that included a new version of HTTPD and the problem went away. They were using BusyBox linux, and apparently there was some other problem with the HTTPD implementation that they had suffered from.

在我原来的问题,我不认为有任何可靠写入套接字代理这样做,除了方式方面。有些我打了运气上面的工作没有设计(因为他们的意思.NET发送整个数据包一气呵成)的解决方法。

In terms of my original question, I don't think there is any reliable way of doing it, apart from writing a socket proxy. Some of the workarounds I played with above worked by luck not design (because they meant .net sent the whole packet in one go).

 
精彩推荐
图片推荐