I have a basic stream which is the stream of HTTP request and
var s=new HttpListener().GetContext().Request.InputStream;
我想读一下溪流(包含非骚扰内容,因为一把包装单寄出)
当我们用精简程序来总结这一流时,我们利用“Reenader”的阅读功能,可以读到整个流,并回击......
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://127.0.0.1/");
listener.Start();
var context = listener.GetContext();
var sr = new StreamReader(context.Request.InputStream);
string x=sr.ReadToEnd(); //This Workds
但是,由于它具有非骚扰性的内容,我们不得不使用StremReader(我尝试了所有编码机制,使用扼杀手段是完全错误的)。 一、使用职能
context.Request.InputStream.Read(buffer,position,Len)
because I cant get the length of the stream, InputStream.Length always throws an exception and cant be used..and i dont want to create a small protocol like [size][file] and read first size then the file ...somehow the StreamReader can get the length ..and i just want to know how . I also tried this and it didn t work
List<byte> bb = new List<byte>();
var ss = context.Request.InputStream;
byte b = (byte)ss.ReadByte();
while (b >= 0)
{
bb.Add(b);
b = (byte)ss.ReadByte();
}
我以以下方式解决了这一问题:
FileStream fs = new FileStream("C:\cygwin\home\Dff.rar", FileMode.Create);
byte[] file = new byte[1024 * 1024];
int finishedBytes = ss.Read(file, 0, file.Length);
while (finishedBytes > 0)
{
fs.Write(file, 0, finishedBytes);
finishedBytes = ss.Read(file, 0, file.Length);
}
fs.Close();
thanks Jon , Douglas