Esempio n. 1
0
 public static void httpPostRequestHandle()
 {
     try
     {
         while (true)
         {
             HttpListenerContext requestContext = publicfunction.g_httpPostRequest.GetContext();
             Thread threadsub = new Thread(new ParameterizedThreadStart((requestcontext) =>
             {
                 System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
                 HttpListenerContext request = (HttpListenerContext)requestcontext;
                 //获取Post请求中的参数和值帮助类
                 HttpListenerPostParaHelper httppost = new HttpListenerPostParaHelper(request);
                 //获取Post过来的参数和数据
                 List <HttpListenerPostValue> lst = httppost.GetHttpListenerPostValue();
                 //bool ibool = true;
                 foreach (var key in lst)
                 {
                     string RtnValue = Encoding.UTF8.GetString(key.datas).Replace("\r\n", "");
                     if (key.name == "capturepic")
                     {
                         publicfunction.g_HttpGetStatus = true;
                         publicfunction.g_HttpGetParams = RtnValue;
                         publicfunction.g_CallMode      = (int)OCXPlayAttrubute.capturepic;
                         publicfunction.rebootTimer();
                     }
                     else if (key.name.Equals("startlnk"))
                     {
                         int i = 0;
                         publicfunction.g_HttpGetStatus = true;
                         publicfunction.g_HttpGetParams = RtnValue;
                         publicfunction.g_CallMode      = (int)OCXPlayAttrubute.startlnkapp;
                         publicfunction.rebootTimer();
                         i++;
                         Console.WriteLine("请求次数:" + i.ToString());
                     }
                     //response
                     request.Response.StatusCode = 200;
                     request.Response.Headers.Add("Access-Control-Allow-Origin", "*");
                     request.Response.ContentType            = "application/json";
                     requestContext.Response.ContentEncoding = Encoding.UTF8;
                     byte[] buffer = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = "true", msg = "提交成功", context = (new { result = "success" }) }));
                     request.Response.ContentLength64 = buffer.Length;
                     var output = request.Response.OutputStream;
                     output.Write(buffer, 0, buffer.Length);
                     output.Close();
                 }
             }));
             threadsub.Start(requestContext);
             Thread.Sleep(200);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Esempio n. 2
0
        public String Print(HttpListenerContext context)
        {
            HttpListenerPostParaHelper httppost = new HttpListenerPostParaHelper(context);

            byte[] fileContent = new byte[] { };
            String content     = httppost.get("data").Substring(httppost.get("data").IndexOf(',') + 1);
            String type        = httppost.get("type");
            String printName   = httppost.get("printName");
            int    rawKind     = Convert.ToInt32(httppost.get("rawKind"));

            try
            {
                switch (httppost.get("mode"))
                {
                case "base64":
                    fileContent = Base64Helper.Base64ToString(content);
                    break;

                case "file":
                default:
                    fileContent = FileHelper.FileToBytes(content);
                    break;
                }
                String path     = System.Environment.CurrentDirectory + "\\Temp\\" + DateTime.Now.ToString("yyyyMMdd") + "\\";
                String filename = path + System.Guid.NewGuid().ToString() + "." + type;
                FileHelper.CreateDirectory(path);
                FileHelper.CreateFile(filename, fileContent);

                Print print = new Print(printName, rawKind);
                print.set(filename, type);
                Thread thread = new Thread(start: new ThreadStart(print.run));
                thread.Start();
            }
            catch (Exception e)
            {
                return("打印失败:" + e.Message);
            }

            return("打印成功");
        }
Esempio n. 3
0
    private static void httpPostRequestHandle()
    {
        while (true)
        {
            HttpListenerContext requestContext = httpPostRequest.GetContext();
            Thread threadsub = new Thread(new ParameterizedThreadStart((requestcontext) => {
                HttpListenerContext request = (HttpListenerContext)requestcontext;

                //获取Post请求中的参数和值帮助类
                HttpListenerPostParaHelper httppost = new HttpListenerPostParaHelper(request);
                //获取Post过来的参数和数据
                List <HttpListenerPostValue> lst = httppost.GetHttpListenerPostValue();

                string userName = "";
                string password = "";
                string suffix   = "";
                string adType   = "";

                //使用方法
                foreach (var key in lst)
                {
                    if (key.Type == 0)
                    {
                        string value = Encoding.UTF8.GetString(key.Data).Replace("\r\n", "");
                        if (key.Name == "username")
                        {
                            userName = value;
                            Console.WriteLine(value);
                        }
                        if (key.Name == "password")
                        {
                            password = value;
                            Console.WriteLine(value);
                        }
                        if (key.Name == "suffix")
                        {
                            suffix = value;
                            Console.WriteLine(value);
                        }
                        if (key.Name == "adtype")
                        {
                            adType = value;
                            Console.WriteLine(value);
                        }
                    }
                    if (key.Type == 1)
                    {
                        string fileName = request.Request.QueryString["FileName"];
                        if (!string.IsNullOrEmpty(fileName))
                        {
                            string filePath = AppDomain.CurrentDomain.BaseDirectory + DateTime.Now.ToString("yyMMdd_HHmmss_ffff") + Path.GetExtension(fileName).ToLower();
                            if (key.Name == "File")
                            {
                                FileStream fs = new FileStream(filePath, FileMode.Create);
                                fs.Write(key.Data, 0, key.Data.Length);
                                fs.Close();
                                fs.Dispose();
                            }
                        }
                    }
                }

                //Response
                request.Response.StatusCode = 200;
                request.Response.Headers.Add("Access-Control-Allow-Origin", "*");
                request.Response.ContentType            = "application/json";
                requestContext.Response.ContentEncoding = Encoding.UTF8;
            }));
            threadsub.Start(requestContext);
        }
    }