Exemplo n.º 1
0
 public void Response()
 {
     if (m_httpMethodData != null)
     {
         m_httpMethodData.Response();
     }
     else
     {
         m_errorData.Response();
     }
 }
        public void Response()
        {
            if (m_errorData != null)
            {
                m_errorData.Response();
            }
            else
            {
                TimeData data = new TimeData();
                //使用Writer输出http响应代码
                using (StreamWriter writer = new StreamWriter(this.m_response.OutputStream))
                {
                    writer.Write(data.ToString());

                    m_response.StatusCode = (int)HttpStatusCode.OK;

                    writer.Close();
                    this.m_response.OutputStream.Close();
                }
            }
        }
        public void Response()
        {
            if (m_errorData != null)
            {
                m_errorData.Response();
            }
            else if (m_versionCheckData != null)
            {
                m_versionCheckData.Response();
            }
            else
            {
                using (FileStream fs = File.OpenRead(m_fileBuffer.FullName))
                {
                    m_response.ContentEncoding = Encoding.UTF8;
                    m_response.ContentLength64 = fs.Length;
                    m_response.SendChunked     = false;
                    m_response.ContentType     = System.Net.Mime.MediaTypeNames.Application.Octet;
                    m_response.AddHeader("Content-disposition", "attachment; filename=" + Path.GetFileName(m_fileBuffer.FullName));

                    byte[] buffer = new byte[1024 * 64];
                    int    read   = 0;
                    using (BinaryWriter bw = new BinaryWriter(m_response.OutputStream))
                    {
                        while ((read = fs.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            bw.Write(buffer, 0, read);
                            bw.Flush();
                        }
                        //response.ContentLength64 = hello.Length;
                        //bw.Write(hello, 0, hello.Length);
                        bw.Close();
                    }
                }
                m_response.StatusCode        = (int)HttpStatusCode.OK;
                m_response.StatusDescription = "OK";
                m_response.OutputStream.Close();
            }
        }
Exemplo n.º 4
0
        public void Response()
        {
            if (m_errorData != null)
            {
                m_errorData.Response();
            }
            else if (m_versionCheckData != null)
            {
                m_versionCheckData.Response();
            }
            else
            {
                using (FileStream fs = File.OpenRead(m_fileBuffer.FullName))
                {
                    m_response.ContentEncoding = Encoding.UTF8;
                    m_response.ContentLength64 = fs.Length;
                    m_response.SendChunked     = false;
                    m_response.ContentType     = StringUtils.GetContneTypeByKey(m_fileBuffer.Extension);
                    m_response.AddHeader("Content-disposition", "attachment; filename=" + m_fileBuffer.Name);

                    byte[] buffer = new byte[1024 * 64];
                    int    read   = 0;
                    using (BinaryWriter bw = new BinaryWriter(m_response.OutputStream))
                    {
                        while ((read = fs.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            bw.Write(buffer, 0, read);
                            bw.Flush();
                        }
                    }
                }
                m_response.StatusCode        = (int)HttpStatusCode.OK;
                m_response.StatusDescription = "OK";
                m_response.OutputStream.Close();
            }
        }