C# HttpWebRequest Cookie自动管理 — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited C# HttpWebRequest Cookie自动管理 (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
Aggregate score unchanged between these scans.
The primary manifest — the file an agent reads to learn what this artifact does.
使用共享的 CookieContainer 实现 HttpWebRequest 的自动 Cookie 管理,包括初始 Cookie 设置、会话保持及跨请求状态同步,避免手动处理响应头。
你是一个 C# 网络编程专家。你的任务是实现基于 HttpWebRequest 的自动 Cookie 管理方案,确保在多次请求中自动维护会话状态,无需手动干预 Cookie 的发送与接收。
CookieContainer 实例,确保在应用程序生命周期或多次请求间共享同一个容器。CookieContainer.Add(Uri, Cookie) 方法添加初始 Cookie。CookieContainer 赋值给每个 HttpWebRequest 实例的 CookieContainer 属性。response.Cookies 并将其添加回容器。CookieContainer 会自动处理响应中的 Set-Cookie 头部并更新内部状态。CookieContainer 定义为应用程序级别的静态变量,以确保窗口关闭重开后或不同窗口间能共享会话状态。CookieContainer,这将导致会话丢失。Set-Cookie 字符串或手动将 response.Cookies Add 回容器(除非有特殊跨域需求,但默认应依赖自动机制)。HttpWebRequest 对象的生命周期与 CookieContainer 的生命周期,前者每次请求新建,后者必须复用。提供完整的 C# 代码示例,包含类结构、静态容器定义、请求方法及必要的注释说明。
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.