修改了http服务器无法正确处理post请求入参;添加了modbus tcp客户端支持。

This commit is contained in:
fengjiayi
2025-07-23 15:57:57 +08:00
parent acf0b87ad0
commit 4e20e816ae
24 changed files with 2466 additions and 189 deletions

View File

@@ -130,7 +130,7 @@ namespace Serein.Library.Network
}
else if (jsonObject != null && PostArgTypes[i] == PostArgType.IsBobyData)
{
args[i] = jsonObject;
args[i] = jsonObject.ToObject(type);
}
else if (jsonObject != null)
{

View File

@@ -36,10 +36,10 @@ namespace Serein.Library.Web
/// <summary>
/// 标记该类为 Web Api 处理类
/// </summary>
public class AutoHostingAttribute : Attribute
public class WebApiControllerAttribute : Attribute
{
public string Url { get; }
public AutoHostingAttribute(string url = "")
public WebApiControllerAttribute(string url = "")
{
this.Url = url;
}

View File

@@ -92,7 +92,7 @@ namespace Serein.Library.Web
{
if (!controllerType.IsClass || controllerType.IsAbstract) return; // 如果不是类或者是抽象类,则直接返回
var autoHostingAttribute = controllerType.GetCustomAttribute<AutoHostingAttribute>();
var autoHostingAttribute = controllerType.GetCustomAttribute<WebApiControllerAttribute>();
var methods = controllerType.GetMethods().Where(m => m.GetCustomAttribute<WebApiAttribute>() != null).ToArray();
@@ -264,7 +264,7 @@ namespace Serein.Library.Web
/// <param name="controllerType">控制器类型</param>
/// <param name="method">方法信息</param>
/// <returns>方法对应的urk</returns>
private string AddRoutesUrl(AutoHostingAttribute autoHostingAttribute, WebApiAttribute webAttribute, Type controllerType, MethodInfo method)
private string AddRoutesUrl(WebApiControllerAttribute autoHostingAttribute, WebApiAttribute webAttribute, Type controllerType, MethodInfo method)
{
string controllerName;
if (string.IsNullOrWhiteSpace(autoHostingAttribute.Url))

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Threading.Tasks;
@@ -47,8 +48,15 @@ namespace Serein.Library.Web
{
while (listener.IsListening)
{
var context = await listener.GetContextAsync(); // 获取请求上下文
ProcessRequestAsync(context); // 处理请求
try
{
var context = await listener.GetContextAsync(); // 获取请求上下文
await ProcessRequestAsync(context); // 处理请求
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
});
}
@@ -84,7 +92,7 @@ namespace Serein.Library.Web
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
private async void ProcessRequestAsync(HttpListenerContext context)
private async Task ProcessRequestAsync(HttpListenerContext context)
{
// 添加CORS头部
context.Response.Headers.Add("Access-Control-Allow-Origin", "*");