c#接收http的post请求的多个文件流

c#服务端接收客户端发送上传多个文件的请求,需要把每个文件流单独取出来,直接上代码

  

 HttpContext context = HttpContext.Current;
            for (int i = 0; i < context.Request.Files.Count; i++)
            {
                try
                {
                    HttpPostedFile aFile = context.Request.Files[i];
                    Stream mystream = aFile.InputStream;
                    StreamReader reader = new StreamReader(mystream);
                    string xml = " ";
                    StringBuilder strXML = new StringBuilder();                
                    while (reader.Peek() >= 0)
                    {
                        string line = reader.ReadLine().Trim();//直接读取一行
                        if (line == null) return null;
                        if (line == String.Empty) continue;
                        if (line.StartsWith("<"))
                        {
                            xml = line.Trim();
                            strXML.Append(xml);
                        }
                    }
                    String xmlData = reader.ReadToEnd();
                    byte[] bytes = System.Text.Encoding.UTF8.GetBytes(strXML.ToString());
                    listContentByte.Add(bytes);
                    Console.WriteLine();

                }
                catch
                {

                }
            }

猜你喜欢

转载自www.cnblogs.com/zhouyuqiu/p/12110901.html