[英].Net HTTP POST FileStream / without using MemoryStream
HttpClient.PostAsync(uri, StreamContent)
seems to use a MemoryStream
behind the scenes even if I create StreamContent
using a FileStream
. 即使我使用
FileStream
创建StreamContent
HttpClient.PostAsync(uri, StreamContent)
似乎也会在后台使用MemoryStream
。 Is there any way to HTTP POST
a FileStream
from .Net without using a MemoryStream
? 有没有办法从.Net通过
HTTP POST
FileStream
而不使用MemoryStream
? Can I modify MS.Internal.InternalWebRequestStream.Write
(see stack trace below) to not use a MemoryStream
? 我可以修改
MS.Internal.InternalWebRequestStream.Write
(请参见下面的堆栈跟踪)以不使用MemoryStream
吗?
Stack trace: 堆栈跟踪:
Exception of type 'System.OutOfMemoryException' was thrown.
at System.IO.MemoryStream.set_Capacity(Int32 value)
at System.IO.MemoryStream.EnsureCapacity(Int32 value)
at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at MS.Internal.InternalWebRequestStream.Write(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.Stream.<BeginWriteInternal>b__11(Object param0)
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
解决方案是使用HttpWebRequest
并按此处所述设置AllowWriteStreamBuffering = false
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.