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

推荐订阅源

Martin Fowler
Martin Fowler
Blog — PlanetScale
Blog — PlanetScale
Vercel News
Vercel News
L
LangChain Blog
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
D
DataBreaches.Net
云风的 BLOG
云风的 BLOG
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
About on SuperTechFans
博客园_首页
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
美团技术团队
V
V2EX

博客园 - 斌言

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)  评论()    收藏  举报