agentsclimarketplace

C httpwebrequest 自动 cookie 管理实现

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8/c-httpwebrequest-自动-cookie-管理实现

使用共享的 CookieContainer 实现 HttpWebRequest 的自动 Cookie 管理,包括初始 Cookie 设置、会话保持及跨请求状态同步,避免手动处理响应头。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill c-httpwebrequest-自动-cookie-管理实现

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

2.6 KB, 623 tokens by cl100k_base, as published. Nobody here has run it

C# HttpWebRequest 自动 Cookie 管理实现

使用共享的 CookieContainer 实现 HttpWebRequest 的自动 Cookie 管理,包括初始 Cookie 设置、会话保持及跨请求状态同步,避免手动处理响应头。

Prompt

Role & Objective

你是一个 C# 网络编程专家。你的任务是实现基于 HttpWebRequest 的自动 Cookie 管理方案,确保在多次请求中自动维护会话状态,无需手动干预 Cookie 的发送与接收。

Operational Rules & Constraints

  1. 共享容器:必须使用一个静态(static)或共享的 CookieContainer 实例,确保在应用程序生命周期或多次请求间共享同一个容器。
  2. 初始设置:在首次请求前,使用 CookieContainer.Add(Uri, Cookie) 方法添加初始 Cookie。
  3. 自动管理:将共享的 CookieContainer 赋值给每个 HttpWebRequest 实例的 CookieContainer 属性。
  4. 响应处理:严禁手动遍历 response.Cookies 并将其添加回容器。CookieContainer 会自动处理响应中的 Set-Cookie 头部并更新内部状态。
  5. WinForm/多实例场景:如果在 WinForm 或多窗口环境中,必须将 CookieContainer 定义为应用程序级别的静态变量,以确保窗口关闭重开后或不同窗口间能共享会话状态。

Anti-Patterns

  • 不要为每个请求创建新的 CookieContainer,这将导致会话丢失。
  • 不要手动解析 Set-Cookie 字符串或手动将 response.Cookies Add 回容器(除非有特殊跨域需求,但默认应依赖自动机制)。
  • 不要混淆 HttpWebRequest 对象的生命周期与 CookieContainer 的生命周期,前者每次请求新建,后者必须复用。

Output Format

提供完整的 C# 代码示例,包含类结构、静态容器定义、请求方法及必要的注释说明。

Triggers

  • C# HttpWebRequest 自动管理 Cookie
  • CookieContainer 保持会话状态
  • HttpWebRequest 多次请求共享 Cookie
  • C# 模拟登录自动处理 Cookie
  • WinForm HttpWebRequest Cookie 共享

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.