HttpHelper.cs 737 B

1234567891011121314151617181920212223
  1. using System.IO;
  2. using System.Net;
  3. using System.Text;
  4. namespace ET.Server
  5. {
  6. public static class HttpHelper
  7. {
  8. public static async ETTask<string> GetBodyParameter(HttpListenerContext context)
  9. {
  10. return await new StreamReader(context.Request.InputStream).ReadToEndAsync();
  11. }
  12. public static void Response(HttpListenerContext context, object response)
  13. {
  14. byte[] bytes = JsonHelper.ToJson(response).ToUtf8();
  15. context.Response.StatusCode = 200;
  16. context.Response.ContentEncoding = Encoding.UTF8;
  17. context.Response.ContentLength64 = bytes.Length;
  18. context.Response.OutputStream.Write(bytes, 0, bytes.Length);
  19. }
  20. }
  21. }