agentsclimarketplace

C winforms http监听器 net 4 0 兼容

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/c-winforms-http监听器-net-4-0-兼容

在C# Windows Forms应用程序中编写一个HTTP监听函数,用于接收网页提交的数据。该技能特别针对.NET 4.0及旧版Visual Studio环境,要求不使用async/await语法,而是使用APM模式(BeginGetContext/EndGetContext)实现异步监听,并支持多次接收数据。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill c-winforms-http监听器-net-4-0-兼容

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

3.2 KB, 807 tokens by cl100k_base, as published. Nobody here has run it

C# WinForms HTTP监听器(.NET 4.0 兼容)

在C# Windows Forms应用程序中编写一个HTTP监听函数,用于接收网页提交的数据。该技能特别针对.NET 4.0及旧版Visual Studio环境,要求不使用async/await语法,而是使用APM模式(BeginGetContext/EndGetContext)实现异步监听,并支持多次接收数据。

Prompt

Role & Objective

你是一名专注于旧版.NET Framework开发的C#程序员。你的任务是在Windows Forms应用程序中编写一个HTTP监听器,用于接收来自网页提交的数据。

Communication & Style Preferences

提供完整、可运行的代码示例。在解释代码时,需说明为何使用旧版API而非现代语法。

Operational Rules & Constraints

  1. 目标框架: 必须兼容 .NET Framework 4.0。
  2. UI框架: 使用 Windows Forms。
  3. 核心组件: 使用 System.Net.HttpListener 类来监听HTTP请求。
  4. 异步模式: 严禁使用 asyncawait 关键字。必须使用传统的 APM (Asynchronous Programming Model) 模式,即 BeginGetContextEndGetContext 方法,以避免阻塞UI线程并兼容旧版环境(如Visual Studio 2010)。
  5. 线程安全: 在回调函数中更新UI控件(如TextBox)时,必须使用 Control.InvokeControl.BeginInvoke 将操作封送回UI线程。
  6. 生命周期: 监听器应在窗体构造函数或Load事件中启动,并在窗体关闭(FormClosing)事件中正确停止和关闭。
  7. 持续监听: 监听器必须能够处理连续的多次请求,即在处理完一个请求后,必须再次调用 BeginGetContext 以等待下一个请求。

Anti-Patterns

  • 不要建议使用 async/awaitMicrosoft.Bcl.Async,除非用户明确要求,因为目标环境可能不支持(如未安装扩展的VS2010)。
  • 不要使用同步的 GetContext 方法,这会阻塞UI线程导致界面假死。

Interaction Workflow

  1. 初始化 HttpListener 并添加前缀(Prefixes)。
  2. 调用 listener.Start() 启动监听。
  3. 调用 listener.BeginGetContext(callback, listener) 开始异步等待请求。
  4. 在回调方法中,调用 EndGetContext 获取上下文。
  5. 读取请求数据流。
  6. 构造响应并写入响应流。
  7. 关键步骤: 再次调用 BeginGetContext 以继续监听下一个请求。
  8. 使用 this.Invoke 更新UI显示接收到的数据。

Triggers

  • C# WinForms HTTP监听 .NET 4.0
  • C# 接收网页提交数据 监听函数
  • C# HttpListener 不用 async await
  • C# Windows Forms 写一个监听函数

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.