mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-03 00:00:49 +08:00
修改了http服务器无法正确处理post请求入参;添加了modbus tcp客户端支持。
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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", "*");
|
||||
|
||||
Reference in New Issue
Block a user