From ac93c4092a21dbf0fa9cf8b9b1302f2d5d183f61 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期一, 09 六月 2025 20:48:20 +0800
Subject: [PATCH] 修改提示字段

---
 project/人脸识别插件/FaceSdkX64/FaceSdkX64Service/HttpServer.cs |   86 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 86 insertions(+), 0 deletions(-)

diff --git "a/project/\344\272\272\350\204\270\350\257\206\345\210\253\346\217\222\344\273\266/FaceSdkX64/FaceSdkX64Service/HttpServer.cs" "b/project/\344\272\272\350\204\270\350\257\206\345\210\253\346\217\222\344\273\266/FaceSdkX64/FaceSdkX64Service/HttpServer.cs"
new file mode 100644
index 0000000..7f13da3
--- /dev/null
+++ "b/project/\344\272\272\350\204\270\350\257\206\345\210\253\346\217\222\344\273\266/FaceSdkX64/FaceSdkX64Service/HttpServer.cs"
@@ -0,0 +1,86 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading.Tasks;
+using static FaceSdkX64Service.TH_Faces;
+
+namespace FaceSdkX64Service
+{
+    public class HttpServer
+    {
+        private string ImgPath = string.Empty;
+
+        HttpListener listener;
+
+        public HttpServer(int port, string imgPath)
+        {
+            ImgPath = imgPath;
+
+            listener = new HttpListener();
+            listener.Prefixes.Add($"http://+:{port}/");
+            listener.Start();
+
+            HttpListenerContext httpListenerContext = listener.GetContext();
+
+            GetConnect(httpListenerContext);
+
+            listener.Stop(); //鍏抽棴HttpListener
+        }
+
+        private void GetConnect(HttpListenerContext context)
+        {
+            try
+            {
+                // 绛夊緟瀹㈡埛绔繛鎺�
+                if (!context.Request.IsWebSocketRequest)
+                {
+                    if (context == null) return;
+                    var request = context.Request;
+                    var response = context.Response;
+
+                    response.StatusCode = 200;
+                    response.ContentType = "text/plain; charset=utf-8";
+                    response.Headers.Add("Access-Control-Allow-Origin", "*"); // 鍏佽璺ㄥ煙璁块棶
+
+                    using (var stream = response.OutputStream)
+                    {
+
+                        // 鎶婂鐞嗕俊鎭繑鍥炲埌瀹㈡埛绔�
+                        if (string.IsNullOrEmpty(ImgPath))
+                        {
+                            stream.Write(new byte[0], 0, 0);
+                        }
+                        else
+                        {
+                            string base64 = ImageToBase64(ImgPath); // 灏嗗浘鐗囪浆鎹负Base64瀛楃涓�
+                            byte[] buffer = Encoding.UTF8.GetBytes(base64);
+                            stream.Write(buffer, 0, buffer.Length);
+                        }
+
+                    }
+
+                }
+
+            }
+            catch (Exception ex)
+            {
+            }
+
+        }
+
+        private string ImageToBase64(string imagePath)
+        {
+            try
+            {
+                byte[] imageBytes = System.IO.File.ReadAllBytes(imagePath);
+                return Convert.ToBase64String(imageBytes);
+            }
+            catch (Exception ex)
+            {
+                return string.Empty;
+            }
+        }
+    }
+}

--
Gitblit v1.9.3