Пример #1
0
        private void RequestProcess(object listenerContext)
        {
            try
            {
                var context = (HttpListenerContext)listenerContext;
                if (null == context)
                {
                    return;
                }
                string param = context.Request.RawUrl;
                RespCreator respCreator = new RespCreator(param);
                string result = respCreator.getResult();

                /*string filename = Path.GetFileName(context.Request.RawUrl);
                filename = "login.json";
                string path = Path.Combine(this.baseFolder, filename);
                byte[] msg;
                if (context.Request.HasEntityBody)
                {
                }
                if (!File.Exists(path))
                {
                    context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    msg = Encoding.UTF8.GetBytes("Sorry, that page does not exist");
                }
                else
                {
                    context.Response.StatusCode = (int)HttpStatusCode.OK;
                    msg = File.ReadAllBytes(path);
                } */
                byte[] msg = Encoding.UTF8.GetBytes(result);
                context.Response.ContentLength64 = msg.Length;
                using (Stream s = context.Response.OutputStream)
                {
                    s.Write(msg, 0, msg.Length);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Request error: " + ex);
            }
        }
Пример #2
0
 private void createResponse()
 {
     RespCreator resp = new RespCreator(_reqRelativePath);
     string result = resp.getResult();
     byte[] respArray = System.Text.UTF8Encoding.UTF8.GetBytes(result);
     _tcpClient.Client.Send(respArray);
     Console.WriteLine("response:{0}", result);
 }