问题描述
我正在尝试以块的形式上传文件以跟踪进度。目前它正确迭代,但我不知道如何构建它以等待响应。现在,当我关闭
流时,它会立即跳转到文件大小0到100%然后上传。 Flushing在流上不起作用,我无法关闭它,因为我正在尝试继续写入它。 SendChunked = true,我不知道我的回答应该是什么。我实际上应该发送一些数据,关闭它,获取另一个请求
流,上传更多,等待响应,获得响应,然后重复?我认为这是非常低效的。
I am trying to upload a file in chunks so as to track progress. Currently it iterates correctly, but I don't know how to structure it to wait for a response. Right now, It is jumping to the file size, 0 - 100% immediately and THEN uploading when I close the stream. Flushing doesn't work on the stream, and I can't close it because I'm trying to continue to write to it. SendChunked = true, and I don't know what my response is supposed to be. Am I actually supposed to send some data, close it, get another request stream, upload more, wait for a response, get response, and then repeat? I think this is extremely inefficient.
推荐答案
See e.g. http://blogs.msdn.com/b/johan/archive/2006/11/15/are-you-getting-outofmemoryexceptions-when-uploading-large-files.aspx ((http://stackoverflow.com/questions/4388689/vb-net-httpwebrequest-fileupload))
完成后,HTTP服务器才会发送响应。 当你的write返回(如果HttpWebRequest没有缓冲,而是直接执行TCP写/发送)所有发生的事情是本地机器上的TCP / IP已将该内容存储在其缓冲区中,准备将
传输到远程机器。 所以只有当你发送更多缓冲区大小等等时才会出现延迟。)
(你的第二个想法不是你所需要的,正如你所怀疑的那样。: - ) 你只需要使用一个HTTP请求。 这是除非服务器知道要拼凑所有从
不同操作中的位到某种方式......)
这篇关于HttpWebRequest上传进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!