谢谢4楼的,不过现在获取是stream属性如下 CanRead false bool CanSeek false bool CanTimeout true bool CanWrite false bool + Length 'stream.Length' threw an exception of type 'System.NotSupportedException' long {System.NotSupportedException} + Position 'stream.Position' threw an exception of type 'System.NotSupportedException' long {System.NotSupportedException} 不能读,不能写。
webform还是mvc?
Stream stream = null;//加入这个就是取得的stream
byte[] bs = new byte[stream.Length];
stream.Read(bs,0,bs.Length);
FileStream fstream = new FileStream("c:\\1.dat", FileMode.Create);
fstream.Write(bs, 0, bs.Length);
fstream.Close();
so = new System.IO.FileStream(filename, System.IO.FileMode.Create);
so.Write();//把stream 流写入
stream .Write();方法
CanSeek false bool
CanTimeout true bool
CanWrite false bool
+ Length 'stream.Length' threw an exception of type 'System.NotSupportedException' long {System.NotSupportedException}
+ Position 'stream.Position' threw an exception of type 'System.NotSupportedException' long {System.NotSupportedException}
不能读,不能写。
不能读,不能写的流能这样?
CanRead =false;
CanSeek=false;
CanWrite=false
{
Stream stream = null;
try
{ HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(uri);
req.AllowAutoRedirect = false;
req.Method = "GET";
req.KeepAlive = false;
using (HttpWebResponse wr = (HttpWebResponse)req.GetResponse())
{//在这里对接收到的页面内容进行处理 stream = getResponseRedirect(wr);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return null;
}
return stream;
} public static Stream getResponseRedirect(HttpWebResponse wr)
{
Stream stream = null;
try
{ String realuri = wr.Headers["Location"];
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(new Uri(realuri));
CookieContainer cc = new CookieContainer();
req.KeepAlive = false; String cookie = wr.Headers["Set-Cookie"];
String[] arr = cookie.Split(';'); cc.SetCookies(new Uri(realuri), arr[0]);
req.CookieContainer = cc;
req.Method = "GET"; using (WebResponse response = req.GetResponse())
{//在这里对接收到的页面内容进行处理
stream = response.GetResponseStream();
} }
catch (Exception e)
{
MessageBox.Show(e.Message);
return null;
}
return stream;
}
ReceiveStream为接收的流,如果能你再去处理readStream
{//在这里对接收到的页面内容进行处理
stream = response.GetResponseStream();
//StreamReader s = new StreamReader(stream);
}
上面那个改一下
WebResponse response = req.GetResponse();
stream = response.GetResponseStream();
呵呵,这个我也刚刚发现,修改了stream对象就可读了。对C# 语法不太了解,谢谢指点。