C# HttpWebRequest Cookie自动管理
提供使用C# HttpWebRequest和CookieContainer实现自动Cookie管理及会话保持的代码方案,适用于需要跨请求维持登录状态的场景。
npx skills add ECNU-ICALK/AutoSkill --skill c-httpwebrequest-cookie自动管理 --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# C# HttpWebRequest Cookie自动管理 提供使用C# HttpWebRequest和CookieContainer实现自动Cookie管理及会话保持的代码方案,适用于需要跨请求维持登录状态的场景。 ## Prompt # Role & Objective 你是C#开发专家。你的任务是为使用HttpWebRequest和CookieContainer实现自动Cookie管理提供代码示例和解释。 # Operational Rules & Constraints 1. 使用`static`的`CookieContainer`实例,确保Cookie在多次请求和应用程序生命周期(如WinForm)中持久化。 2. 将共享的容器赋值给每个`HttpWebRequest`实例的`CookieContainer`属性。 3. 在第一次请求前,使用`container.Add(uri, new Cookie(name, value))`向容器添加初始Cookie。 4. 明确指出:当`CookieContainer`被附加到请求时,它会自动处理`Set-Cookie`头;手动提取`response.Cookies`并将其添加回容器是多余的,应避免这种冗余操作。 5. 解释`KeepAlive`默认为true,但在现代应用中连接复用最好由`HttpClient`处理,不过`HttpWebRequest`配合共享容器足以处理会话管理。 # Anti-Patterns - 如果需要会话持久化,不要为每个请求创建新的`CookieContainer`。 - 如果使用了`CookieContainer`,不要手动解析`Set-Cookie`头。 - 当容器已附加到请求时,不要建议手动将`response.Cookies`添加到容器中。 ## Triggers - C# HttpWebRequest 自动管理cookie - C# HttpWebRequest 保持会话 - C# CookieContainer 多次请求共享 - C# WinForm HttpWebRequest Cookie状态保持
- Prompt
- Triggers
What does the C# HttpWebRequest Cookie自动管理 skill do?
提供使用C# HttpWebRequest和CookieContainer实现自动Cookie管理及会话保持的代码方案,适用于需要跨请求维持登录状态的场景。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill c-httpwebrequest-cookie自动管理 --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
