1

我正在使用 StreamWriter 通过 WebRequest POST 传递大量数据(30mb+)。它失败并显示错误流不支持并发 IO 读取或写入操作。与错误消息相反,我没有执行并发操作——应用程序是单线程的,StreamWriter 逻辑非常简单。

string data = "......."; // 30mb+ of text

var webRequest = WebRequest.Create(someUrl);
webRequest.Method = "POST";
webRequest.ContentLength = data.Length;

using (var writer = new StreamWriter(webRequest.GetRequestStream()))
    writer.Write(data);

我怀疑大量数据是罪魁祸首。我已经看到 Team Foundation System 用户在上传大文件( [1][2] )时收到此错误的引用,但是我没有看到大数据被讨论为 TFS 讨论之外的原因。

我真的遇到了 StreamWriter 的一些限制吗?有没有更有效的方式来传输这些数据?

4

1 回答 1

1

The root problem was my POST request was so large that I had exceeded the target server's maxAllowedContentLength setting. The fix was to increase the value of this setting.

I'm not sure why I got a "concurrent IO" error but it only happened when I set webRequest.ContentLength. When I commented that line out I was able to see the WebRequest received a 404 from the server. This eventually led me to discover the issue with maxAllowedContentLength.

于 2013-05-29T14:18:31.257 回答