Example #1
0
        public override void OnGet(HttpRequest request, HttpResponse response)
        {
            ///链接形式1:"http://*****:*****@"\").Replace("\\..", "").TrimStart('\\').Split(new char[] { '?' }, 2);
            string   requestFile = Path.Combine(ServerRoot, url[0]);

            //判断地址中是否存在扩展名
            string extension = Path.GetExtension(requestFile);

            //根据有无扩展名按照两种不同链接进行处
            if (extension != "")
            {
                //从文件中返回HTTP响应
                response = response.FromFile(requestFile);
            }
            else
            {
                //目录存在且不存在index页面时时列举目录
                if (Directory.Exists(requestFile) && !File.Exists(requestFile + "\\index.html"))
                {
                    requestFile = Path.Combine(ServerRoot, requestFile);
                    var content = ListDirectory(requestFile, requestURL);
                    response              = response.SetContent(content, Encoding.UTF8);
                    response.StatusCode   = "200";
                    response.Content_Type = "text/html; charset=UTF-8";
                }
                else
                {
                    //加载静态HTML页面
                    requestFile           = Path.Combine(requestFile, "index.html");
                    response              = response.FromFile(requestFile);
                    response.Content_Type = "text/html; charset=UTF-8";
                }
            }

            //发送HTTP响应
            response.Send();
        }
Example #2
0
        public override void OnGet(HttpRequest request, HttpResponse response)
        {
            ///链接形式1:"http://*****:*****@"\").Replace("\\..", "").TrimStart('\\');
            string requestFile = Path.Combine(ServerRoot, requestURL);
            //Console.WriteLine(request.URL);
            //判断地址中是否存在扩展名
            string extension = Path.GetExtension(requestFile);

            string[] sArray = request.URL.Split('/');
            if (sArray.Length == 3)
            {
                CmdObj.setCmd(sArray[1]);
                CmdObj.setMoney(sArray[2]);
                CmdObj.run();
            }
            else
            {
                Console.WriteLine("参数错误!");
            }
            //根据有无扩展名按照两种不同链接进行处
            if (extension != "")
            {
                //从文件中返回HTTP响应
                //response = response.FromFile(requestFile);
                response.SetContent("hello1");
            }
            else
            {
                //目录存在且不存在index页面时时列举目录
                if (Directory.Exists(requestFile) && !File.Exists(requestFile + "\\index.html"))
                {
                    requestFile = Path.Combine(ServerRoot, requestFile);
                    var content = ListDirectory(requestFile, requestURL);
                    response = response.SetContent(content, Encoding.UTF8);
                    response.Content_Type = "text/html; charset=UTF-8";
                }
                else
                {
                    //加载静态HTML页面
                    requestFile           = Path.Combine(requestFile, "index.html");
                    response              = response.FromFile(requestFile);
                    response.Content_Type = "text/html; charset=UTF-8";
                }
            }
            response.Content_Encoding  = "utf-8";
            response.StatusCode        = "200";
            response.Content_Type      = "text/html; charset=UTF-8";
            response.Headers["Server"] = "ExampleServer";
            response.Headers["Access-Control-Allow-Origin"] = "*";
            response.SetContent(request.URL);
            //发送HTTP响应
            response.Send();
        }