【发布时间】:2026-01-29 14:15:02
【问题描述】:
我们需要对我们的移动设备发送的大型 http 请求进行分块。这些较小的块流被合并到服务器上的一个文件中。一旦收到所有块,我们需要一种方法将保存的合并请求提交给同一控制器中的另一个方法(Action),该方法将处理这个大的 http 请求。如何才能做到这一点?我们在下面尝试的代码导致服务挂起。有没有办法在没有往返的情况下做到这一点?
//Open merged chunked file
FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
//Read steam support variables
int bytesRead = 0;
byte[] buffer = new byte[1024];
//Build New Web Request. The target Action is called "Upload", this method we are in is called "UploadChunk"
HttpWebRequest webRequest;
webRequest = (HttpWebRequest)WebRequest.Create(Request.Url.ToString().Replace("Chunk", string.Empty));
webRequest.Method = "POST";
webRequest.ContentType = "text/xml";
webRequest.KeepAlive = true;
webRequest.Timeout = 600000;
webRequest.ReadWriteTimeout = 600000;
webRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
Stream webStream = webRequest.GetRequestStream(); //Hangs here, no errors, just hangs
我已经研究过使用 RedirectToAction 和 RedirecctToRoute,但这些方法不适合我们想要做的事情,因为我们无法编辑 Request.InputStream(因为它是只读的)来执行大型请求流。
【问题讨论】:
标签: asp.net-mvc