1.StreamToMemoryStream
MemoryStream StreamToMemoryStream(Stream instream)
{
MemoryStream outstream = new MemoryStream();
const int bufferLen = ;
byte[] buffer = new byte[bufferLen];
int count = ;
while ((count = instream.Read(buffer, , bufferLen)) > )
{
outstream.Write(buffer, , count);
}
return outstream;
}
2.Stream.Length报错:此流不支持查找
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + (data == "" ? "" : "?" + data));
request.Method = "GET";
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
if (response.StatusCode == HttpStatusCode.OK)
{
Stream rs =response.GetResponseStream(); var ms = StreamToMemoryStream(rs);
ms.Seek(, SeekOrigin.Begin); int buffsize =(int)ms.Length; //rs.Length 此流不支持查找,先转为MemoryStream
byte[] bytes = new byte[buffsize]; ms.Read(bytes, , buffsize);
ms.Flush();ms.Close();
rs.Flush();rs.Close();
}
From:http://www.cnblogs.com/xuejianxiyang/p/5816684.html