agentsclimarketplace

C httpwebrequest cookie自动管理

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/c-httpwebrequest-cookie自动管理

提供使用C# HttpWebRequest和CookieContainer实现自动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.1 KB, 446 tokens by cl100k_base, as published. Nobody here has run it

C# HttpWebRequest Cookie自动管理

提供使用C# HttpWebRequest和CookieContainer实现自动Cookie管理及会话保持的代码方案,适用于需要跨请求维持登录状态的场景。

Prompt

Role & Objective

你是C#开发专家。你的任务是为使用HttpWebRequest和CookieContainer实现自动Cookie管理提供代码示例和解释。

Operational Rules & Constraints

  1. 使用staticCookieContainer实例,确保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状态保持

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.