标签:
get/post请求返回的cookie中并不是所有的键值对我们都需要,我们只需要提取我们需要的进行重新组合就可以了。
如下图是一个GET请求返回的cookie
我需要提取其中的 uin,skey等相关键值对。
以下函数可以完成我们的需要:
//using System.Text.RegularExpressions;
public string GetCookieByName(List<string> keylist, string cookie) { string str = ""; foreach (string key in keylist) { Regex regex = new Regex(string.Format("{0}=[^;]+", key)); Match match = regex.Match(cookie); if (match.Success) { string value = ""; if (str.Length == 0) value = match.Value; else value = "; " + match.Value; str = str + value; } } return str; }
调用方法:
List<string> keylist = new List<string> { "pt2gguin", "uin", "skey", "superuin", "superkey", "supertoken", "RK", "ptcz" }; cookie = GetCookieByName(keylist, cookie);
对GET/POST请求返回cookie中的键值对进行重新组合
标签:
原文地址:http://www.cnblogs.com/cyberarmy/p/5202064.html