Esempio n. 1
0
        public override void OnPost(HttpRequest request, HttpResponse response)
        {
            //获取客户端传递的参数
            //string data = request.Params == null ? "" : string.Join(";", request.Params.Select(x => x.Key + "=" + x.Value).ToArray());

            var returnMessage = "";

            try
            {
                if (this.OnPostRequestReceived == null)
                {
                    returnMessage = "打印服务器配置不正确,请联系系统管理员";
                }
                else
                {
                    returnMessage = this.OnPostRequestReceived(request, request.Body);
                }
            }
            catch (Exception ex)
            {
                returnMessage = "unhanlded exception :" + ex.Message;
            }

            //设置返回信息

            string jsonResult = "{\"code\":200, \"msg\":\"" + returnMessage + "\"}";

            //构造响应报文
            response.SetContent(jsonResult);
            response.Content_Encoding = "utf-8";
            response.StatusCode       = "200";
            response.Content_Type     = "text/json; charset=UTF-8";
            response.Headers          = new Dictionary <string, string>();
            response.SetHeader("Access-Control-Allow-Origin", "*");
            //response.SetHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Cookie, Accept");
            //response.SetHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, OPTIONS");
            //response.SetHeader("Access-Control-Allow-Credentials", "true");

            //response.SetHeader("Server", "ExampleServer");

            //发送响应
            response.Send();
        }
Esempio n. 2
0
        public override void OnPost(HttpRequest request, HttpResponse response)
        {
            //获取客户端传递的参数
            string data = request.Params == null ? "" : string.Join(";", request.Params.Select(x => x.Key + "=" + x.Value).ToArray());

            //设置返回信息
            string content = string.Format("这是通过Post方式返回的数据:{0}", data);

            //构造响应报文
            response.SetContent(content);
            response.Content_Encoding = "utf-8";
            response.StatusCode       = "200";
            response.Content_Type     = "text/html; charset=UTF-8";
            response.Headers          = new Dictionary <string, string>();
            response.SetHeader(ResponseHeaders.Server, "127.0.0.1");
            response.Headers["Server"] = "ExampleServer";

            //发送响应
            response.Send();
        }