惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
L
LangChain Blog
Jina AI
Jina AI
爱范儿
爱范儿
C
Check Point Blog
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
月光博客
月光博客
GbyAI
GbyAI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Stack Overflow Blog
Stack Overflow Blog
V
V2EX
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Microsoft Azure Blog
Microsoft Azure Blog
The GitHub Blog
The GitHub Blog
博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题

博客园 - 斌言

Claude Code + deepseek在Windows环境上的搭建教程 docker部署.NET6并挂载目录 unable to access 'https://github.com/langgenius/dify.git/': Failed to connect to github.com port 443 after 21111 ms: Could not connect to server .NET6 MVC 无刷新上传文件 docker快速搭建部署mqtt ubuntu安装smaba CentOS7.9安装Docker centos7.9 安装 openGauss 5.0.0 CentOS 7 yum安装MongoDB CentOS 7.4安装.NET6 react native SectionList组件实现多选 react-native-vector-icons 安装 apk文件查看指纹证书方法 server2008 安装mongodb supervisor 安装及基本使用 ASP.NET Core http请求内容过大, IIS服务器 返回 Request Too Long 解决方案 ASP.NET Core MVC中调用Json()时默认使用Newtonsoft.Json返回数据 react native android9 axios network error .NET Core3.1升级.NET5 oracle连接报错
WinForms 嵌入 Web服务
斌言 · 2021-09-13 · via 博客园 - 斌言

1、首先安装一个Kestrel服务器包

Microsoft.AspNetCore.Server.Kestrel

2、在Main方法中插入如下代码

static class Program
    {
        /// <summary>
        ///  The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var host = new WebHostBuilder()
                .UseKestrel()
                 .Configure(ConfigureWebApp)
                .UseContentRoot(Directory.GetCurrentDirectory())
               .UseUrls("http://*:5001").Build();
            host.Run();
Application.Run(
new Form1()); } private static void ConfigureWebApp(IApplicationBuilder app) { app.Run(Request); } private static async Task Request(HttpContext context) { // 处理非静态请求 var request = context.Request; var response = context.Response; string path = request.Path.Value; response.ContentType = "application/json; charset=UTF-8"; bool hasRun = true; if (path == "/report") { string value = request.Query["value"]; response.StatusCode = 200; } else { response.StatusCode = 404; } } }

3、启动窗体  在浏览器输入http://127.0.0.1:5001/report 即可调用 Request 方法中对应的逻辑

posted @ 2021-09-13 16:02  斌言  阅读(335)  评论()    收藏  举报