如何增加数据包大小以读取网络响应
我正在使用 httpWebResponse
从 web url(在我们自己的网络中)读取响应。使用StreamReader ReadToEnd()
读取响应时,它会以数据包的形式获取数据,每个数据包的大小约为500字节
。
如何将此数据包大小增加到大约 512 KB
?
I am reading response from a web url (in our own network), using httpWebResponse
. While reading the response using StreamReader ReadToEnd()
, It fetching data in packets and each packet having size of approx 500 bytes
.
How can I increase this packet size to approx 512 KB
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数据包大小(主要)不取决于获取代码 - 它取决于服务器发送的数据包大小,并且这些数据包可能会被网络的其余部分进一步分割。
你根本不可能拥有 512K 的 TCP/IP 数据包...而且你不应该在意。这就是 TCP/IP 的工作原理;它并不是对数据发出多个 HTTP 请求,而是使用普通的 TCP/IP 通道。
看一下从浏览器获取相同的数据 - 您会看到它以相同的方式分成数据包。
编辑:我从您的评论中看到获取数据需要 4 秒。是的,这是相当长的时间 - 但这很可能只是获取/创建和传输数据所需的时间。您在这里并没有真正给出太多上下文(什么是“网络用户”?),但我认为您试图在错误的地方进行优化。
The packet size isn't (primarily) up to the fetching code - it's up to the server what size of packet it sends out, and those packets may be further split up by the rest of the network.
You simply can't have a TCP/IP packet of 512K... and you shouldn't care. This is just how TCP/IP works; it's not like it's making several HTTP requests for the data, it's just using the normal TCP/IP channel.
Have a look at fetching the same data from a browser - you'll see it split into packets in the same way.
EDIT: I see from your comments that it's taking 4 seconds to get the data. Yes, that's quite a long time - but that may well just be how long it takes to fetch/create and transport the data. You haven't really given much context here (what's a "webuser"?) but I think you're trying to optimize in the wrong place.