Skip to content
Back to skills

C Httpwebrequest Cookie自动管理

ASecurity

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

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
ai-agentsc#

Works with

  • cli

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill 'c-httpwebrequest-cookie自动管理' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of C Httpwebrequest Cookie自动管理?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for C Httpwebrequest Cookie自动管理
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-c-httpwebrequest-cookie-meta-skill-evloving/badge)](https://www.skillsdirectory.com/skills/david-li0406-c-httpwebrequest-cookie-meta-skill-evloving)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "74d2dff2-c460-4195-99a7-5b30ce97455b"
name: "C# HttpWebRequest Cookie自动管理"
description: "提供使用C# HttpWebRequest和CookieContainer实现自动Cookie管理及会话保持的代码方案,适用于需要跨请求维持登录状态的场景。"
version: "0.1.0"
tags:
  - "C#"
  - "HttpWebRequest"
  - "CookieContainer"
  - "会话管理"
  - "网络编程"
triggers:
  - "C# HttpWebRequest 自动管理cookie"
  - "C# HttpWebRequest 保持会话"
  - "C# CookieContainer 多次请求共享"
  - "C# WinForm HttpWebRequest Cookie状态保持"
---

# 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状态保持

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…