我的解决办法:用下面红色的行,替换掉注释行,不设置ContentLength
代码片断:
HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(BaseUrl);
httpReq.Method = "POST"; //对发送的数据不使用缓存
httpReq.AllowWriteStreamBuffering = false; //设置获得响应的超时时间(300秒)
httpReq.Timeout = 300000;
httpReq.ContentType = "multipart/form-data; boundary=" + strBoundary;
long length = fs.Length + postHeaderBytes.Length + boundaryBytes.Length;
long fileLength = fs.Length;
httpReq.SendChunked = true;
//httpReq.ContentLength = length;
本文介绍了一种改进HTTP POST请求的方法,通过调整HttpWebRequest属性来优化文件上传过程,具体包括禁用缓存、设置流缓冲、定义请求超时及启用分块发送等功能。
1587

被折叠的 条评论
为什么被折叠?



