C# Stream.ReadTimeout 解决方案
错误描述: 使用 StreamReader 无法读取 Stream
using (MemoryStream ms = new MemoryStream()) { StreamReader sr = new StreamReader(ms); string strMemory = sr.ReadToEnd(); //这里报ReadTimeout 异常,而无法读取 }
解决方案:
1:先将Sream转化为 byte[];
2:在将byte[]转化为string即可
using (MemoryStream ms = new MemoryStream()) { tempFile.FileContent.CopyTo(ms); byte[] getMem = ms.ToArray(); string imgStr = System.Text.Encoding.UTF8.GetString(getMem); }