一个好用的C# HttpCookieHelper.cs类
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions; namespace DotNet.Utilities
{
/// <summary>
/// Cookie操作帮助类
/// </summary>
public static class HttpCookieHelper
{
/// <summary>
/// 根据字符生成Cookie列表
/// </summary>
/// <param name="cookie">Cookie字符串</param>
/// <returns></returns>
public static List<CookieItem> GetCookieList(string cookie)
{
List<CookieItem> cookielist = new List<CookieItem>();
foreach (string item in cookie.Split(new string[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries))
{
if (Regex.IsMatch(item, @"([\s\S]*?)=([\s\S]*?)$"))
{
Match m = Regex.Match(item, @"([\s\S]*?)=([\s\S]*?)$");
cookielist.Add(new CookieItem() { Key = m.Groups[].Value, Value = m.Groups[].Value });
}
}
return cookielist;
} /// <summary>
/// 根据Key值得到Cookie值,Key不区分大小写
/// </summary>
/// <param name="Key">key</param>
/// <param name="cookie">字符串Cookie</param>
/// <returns></returns>
public static string GetCookieValue(string Key, string cookie)
{
foreach (CookieItem item in GetCookieList(cookie))
{
if (item.Key == Key)
return item.Value;
}
return "";
}
/// <summary>
/// 格式化Cookie为标准格式
/// </summary>
/// <param name="key">Key值</param>
/// <param name="value">Value值</param>
/// <returns></returns>
public static string CookieFormat(string key, string value)
{
return string.Format("{0}={1};", key, value);
}
} /// <summary>
/// Cookie对象
/// </summary>
public class CookieItem
{
/// <summary>
/// 键
/// </summary>
public string Key { get; set; }
/// <summary>
/// 值
/// </summary>
public string Value { get; set; }
}
}
一个好用的C# HttpCookieHelper.cs类的更多相关文章
- 微软版的SqlHelper.cs类
一,微软SQLHelper.cs类 中文版: using System; using System.Data; using System.Xml; using System.Data.SqlClien ...
- WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据
WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据 WebForm1.aspx 页面 (原生AJAX请求,写法一) <%@ Page Langu ...
- 微软SQLHelper.cs类 中文版
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Co ...
- 存储过程及Comm.cs类的创建
2013-09-25 13:08:59 一.准备工作 首先创建一个数据库,如创建“试用期公务员管理”数据库:再创建一个Comm.cs类,添加代码如下: using System;using Syste ...
- 【protobuf进阶】通过.proto文件导出C#支持的.cs类文件
protobuf是一个跨平台的消息交互协议,类似xml.json等. protocolbuffer(以下简称PB)是google 的一种数据交换的格式,它独立于语言,独立于平台.google 提供了多 ...
- 微软SQLHelper.cs类
using System; using System.Data; using System.Xml; using System.Data.SqlClient; using System.Collect ...
- WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据(转)
WebForm.aspx 页面通过 AJAX 访问WebForm.aspx.cs类中的方法,获取数据 WebForm1.aspx 页面 (原生AJAX请求,写法一) <%@ Page Langu ...
- 设计模式(一)单例模式:创建模式 ASPNET CORE WEB 应用程序的启动 当项目中 没有STARTUP.CS 类如何设置启动 配置等等
设计模式(一)单例模式:创建模式 先聊一下关于设计的几个原则(1)单一原则(SRP):一个类应该仅有一个引起它变化的原因 :意思就是 (一个类,最好只负责一件事情,并且只有一个引起它变化的原因(2)开 ...
- 处女篇:自用C#后端SqlHelper.cs类
自用SqlHelper.cs类,此类来自软谋教育徐老师课程SqlHelper.cs! using System; using System.Collections; using System.Coll ...
随机推荐
- python 正则,os,sys,hashlib模块
简单的小算法 random随机获取数据 import random def getrandata(num): a=[] i= while i<num: a.append(random.randi ...
- collectd配置
udp proxy - 192.168.48.112 cat > /etc/collectd_25801.conf << EOF Hostname "kvm-48-112& ...
- 用python管理Cisco路由器
目前DevOps是整个运维发展的方向,Network的运维也一样.使用程序控制底层的路由器是最基本的要求之一. 本文简单解释如何用Python控制路由器,对网络设备进行配置. Python和网络设备连 ...
- May 18th 2017 Week 20th Thursday
The greater the struggle, the more glorious the triumph. 挑战愈艰巨,胜利愈辉煌. Sometimes it would be better t ...
- 数据结构与算法分析java——树2(二叉树类型)
1. 二叉查找树 二叉查找树(Binary Search Tree)/ 有序二叉树(ordered binary tree)/ 排序二叉树(sorted binary tree) 1). 若任意节点 ...
- android-ndk-r7b编译环境Cygwin工具搭建及配置(转)
开发android ndk 的时候需要一个编译工具编译c程序,ndk需要linux下编译,所以win环境下提供Cygwin模拟linux编译C android-ndk 较低版本的这个工具的配置网上很多 ...
- Apache轻量级性能測试工具--ab
Apache轻量级性能測试工具--ab ab早已不是什么新奇玩意,平时工作中会须要一些性能測试.简单的性能測试全然能够由AB来替代,而不须要动用LR这样重量级的工具. 此文简介一下ab的工具使用与结果 ...
- Bokeh 学习
这段时间由于在做K-means对文本进行处理,需要进行绘图,实验室编程大哥向我介绍了Bokeh来进行绘图,一直是根据自己的需求来进行对其探索,今儿个看到一篇博文,对Bokeh进行了详细的解说,做个笔记 ...
- sudo: Sorry, you must have a tty to run
The requiretty option in sudoers file The requiretty if set in sudo config file sudoers, sudo will o ...
- $CRS_HOME/cdata下大量数字命名的文件,占用空间大
问题现象: <CRS_HOME>/cdata目录下存在大量数字命名的文件,导致文件系统爆满 $ls -alrth /opt/oracle/product/CRS/cdata/crs ...