Пример #1
0
 private static void ResponseFile(HttpListenerResponse response, string fileName, int statusCode = 200)
 {
     try
     {
         response.ContentType = MIMETypeProcess.GetMimeType(fileName);
         response.StatusCode  = statusCode;
         var fs = File.ReadAllBytes(fileName);
         response.ContentLength64 = fs.LongLength;
         var os = response.OutputStream;
         os.Write(fs, 0, fs.Length);
         os.Close();
         fs = null;
         response.Close();
     }
     catch
     {
     }
 }
Пример #2
0
 private static void ResponseTxt(HttpListenerResponse response, string txt, string extention = ".txt",
                                 int statusCode = 200)
 {
     try
     {
         var buffer = Encoding.UTF8.GetBytes(txt);
         response.ContentType     = MIMETypeProcess.GetMimeType(extention);
         response.StatusCode      = statusCode;
         response.ContentLength64 = buffer.Length;
         var os = response.OutputStream;
         os.Write(buffer, 0, buffer.Length);
         os.Close();
         response.Close();
     }
     catch
     {
     }
 }