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
                {

                }
            }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM