cookie包含什么信息属性值不能包含符号吗

实际上,这段代码是网上的,但是由于设置Cookie相对麻烦,所以增加了设置Cookie的方法.另外,对Cookie中的’,'符号进行了转意,用了3个多月了,没有发现有什么问题,好久没有发文章了,今天抽空就发出来把 ^ ^using Susing System.Collections.Gusing System.Lusing System.Nusing System.Tnamespace JointOfficial.Model{&&&&/// &summary&&&&&/// 支持 Session 和 Cookie 的 WebClient。&&&&/// &/summary&&&&&public class HttpClient : WebClient&&&&{&&&&&&&&// Cookie 容器&&&&&&&&private CookieContainer cookieC&&&&&&&&/// &summary&&&&&&&&&/// 创建一个新的 WebClient 实例。&&&&&&&&/// &/summary&&&&&&&&&public HttpClient()&&&&&&&&{&&&&&&&&&&&&this.cookieContainer = new CookieContainer();&&&&&&&&}&&&&&&&&/// &summary&&&&&&&&&/// 创建一个新的 WebClient 实例。&&&&&&&&/// &/summary&&&&&&&&&/// &param name=&cookie&&Cookie 容器&/param&&&&&&&&&public HttpClient(CookieContainer cookies)&&&&&&&&{&&&&&&&&&&&&this.cookieContainer =&&&&&&&&}&&&&&&&&/// &summary&&&&&&&&&/// Cookie 容器&&&&&&&&/// &/summary&&&&&&&&&public CookieContainer Cookies&&&&&&&&{&&&&&&&&&&&&get { return this.cookieC }&&&&&&&&&&&&set { this.cookieContainer = }&&&&&&&&}&&&&&&&&/// &summary&&&&&&&&&/// 坑爹之用&&&&&&&&/// &/summary&&&&&&&&&public object Tag { }&&&&&&&&/// &summary&&&&&&&&&///
设置Cookie&&&&&&&&/// &/summary&&&&&&&&&/// &param name=&cookieString& type=&string&&&&&&&&&&///
&para&&&&&&&&&///
以String存储的Cookie&&&&&&&&///
&/para&&&&&&&&&/// &/param&&&&&&&&&/// &param name=&domain& type=&string&&&&&&&&&&///
&para&&&&&&&&&///
Cookie的作用域&&&&&&&&///
&/para&&&&&&&&&/// &/param&&&&&&&&&/// &returns&&&&&&&&&///
A System.Net.CookieContainer value...&&&&&&&&/// &/returns&&&&&&&&&public CookieContainer SetCookies(string cookieString, string domain)&&&&&&&&{&&&&&&&&&&&&string[] tempCookies = cookieString.Split(';');&&&&&&&&&&&&string tempCookie =&&&&&&&&&&&&int Equallength = 0;//
=的位置 &&&&&&&&&&&&string cookieKey =&&&&&&&&&&&&string cookieValue =&&&&&&&&&&&&CookieContainer cc = new CookieContainer();&&&&&&&&&&&&for (int i = 0; i & tempCookies.L i++)&&&&&&&&&&&&{&&&&&&&&&&&&&&&&if (!string.IsNullOrEmpty(tempCookies[i]))&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&tempCookie = tempCookies[i];&&&&&&&&&&&&&&&&&&&&Equallength = tempCookie.IndexOf(&=&);&&&&&&&&&&&&&&&&&&&&if (Equallength != -1)
//有可能cookie 无=,就直接一个cookiename;比如:a=3;abc=; &&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&cookieKey = tempCookie.Substring(0, Equallength).Trim();&&&&&&&&&&&&&&&&&&&&&&&&if (Equallength == tempCookie.Length - 1)
//这种是等号后面无值,如:abc=; &&&&&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&&&&&cookieValue = &&;&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&&&&&cookieValue = tempCookie.Substring(Equallength + 1, tempCookie.Length - Equallength - 1).Trim();&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&else&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&cookieKey = tempCookie.Trim();&&&&&&&&&&&&&&&&&&&&&&&&cookieValue = &&;&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&cookieValue = cookieValue.Replace(&,&, &%2C&);//针对Cookie中的特殊符号','进行转换&&&&&&&&&&&&&&&&&&&&cc.Add(new Cookie(cookieKey, cookieValue, &&, domain));&&&&&&&&&&&&&&&&}&&&&&&&&&&&&}&&&&&&&&&&&&this.Cookies =&&&&&&&&&&&&&&&&&&&&}&&&&&&&&/// &summary&&&&&&&&&/// 返回带有 Cookie 的 HttpWebRequest。&&&&&&&&/// &/summary&&&&&&&&&/// &param name=&address&&&/param&&&&&&&&&/// &returns&&/returns&&&&&&&&&protected override WebRequest GetWebRequest(Uri address)&&&&&&&&{&&&&&&&&&&&&WebRequest request = base.GetWebRequest(address);&&&&&&&&&&&&if (request is HttpWebRequest)&&&&&&&&&&&&{&&&&&&&&&&&&&&&&HttpWebRequest httpRequest = request as HttpWebR&&&&&&&&&&&&&&&&httpRequest.CookieContainer = cookieC&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&}&&&&&&&&#region 封装了PostData, GetSrc 和 GetFile 方法&&&&&&&&/// &summary&&&&&&&&&/// 向指定的 URL POST 数据,并返回页面&&&&&&&&/// &/summary&&&&&&&&&/// &param name=&uriString&&POST URL&/param&&&&&&&&&/// &param name=&postString&&POST 的 数据&/param&&&&&&&&&/// &param name=&postStringEncoding&&POST 数据的 CharSet&/param&&&&&&&&&/// &param name=&dataEncoding&&页面的 CharSet&/param&&&&&&&&&/// &returns&页面的源文件&/returns&&&&&&&&&public string PostData(string uriString, string postString, string postStringEncoding, string dataEncoding, out string msg)&&&&&&&&{&&&&&&&&&&&&try&&&&&&&&&&&&{&&&&&&&&&&&&&&&&// 将 Post 字符串转换成字节数组&&&&&&&&&&&&&&&&byte[] postData = Encoding.GetEncoding(postStringEncoding).GetBytes(postString);&&&&&&&&&&&&&&&&this.Headers.Add(&Content-Type&, &application/x-www-form-urlencoded&);&&&&&&&&&&&&&&&&// 上传数据,返回页面的字节数组&&&&&&&&&&&&&&&&byte[] responseData = this.UploadData(uriString, &POST&, postData);&&&&&&&&&&&&&&&&// 将返回的将字节数组转换成字符串(HTML);&&&&&&&&&&&&&&&&string srcString = Encoding.GetEncoding(dataEncoding).GetString(responseData);&&&&&&&&&&&&&&&&srcString = srcString.Replace(&\t&, &&);&&&&&&&&&&&&&&&&srcString = srcString.Replace(&\r&, &&);&&&&&&&&&&&&&&&&srcString = srcString.Replace(&\n&, &&);&&&&&&&&&&&&&&&&msg = string.E&&&&&&&&&&&&&&&&return srcS&&&&&&&&&&&&}&&&&&&&&&&&&catch (WebException we)&&&&&&&&&&&&{&&&&&&&&&&&&&&&&msg = we.M&&&&&&&&&&&&&&&&return string.E&&&&&&&&&&&&}&&&&&&&&}&&&&&&&&/// &summary&&&&&&&&&/// 获得指定 URL 的源文件&&&&&&&&/// &/summary&&&&&&&&&/// &param name=&uriString&&页面 URL&/param&&&&&&&&&/// &param name=&dataEncoding&&页面的 CharSet&/param&&&&&&&&&/// &returns&页面的源文件&/returns&&&&&&&&&public string GetSrc(string uriString, string dataEncoding, out string msg)&&&&&&&&{&&&&&&&&&&&&try&&&&&&&&&&&&{&&&&&&&&&&&&&&&&// 返回页面的字节数组&&&&&&&&&&&&&&&&byte[] responseData = this.DownloadData(uriString);&&&&&&&&&&&&&&&&// 将返回的将字节数组转换成字符串(HTML);&&&&&&&&&&&&&&&&string srcString = Encoding.GetEncoding(dataEncoding).GetString(responseData);&&&&&&&&&&&&&&&&srcString = srcString.Replace(&\t&, &&);&&&&&&&&&&&&&&&&srcString = srcString.Replace(&\r&, &&);&&&&&&&&&&&&&&&&srcString = srcString.Replace(&\n&, &&);&&&&&&&&&&&&&&&&msg = string.E&&&&&&&&&&&&&&&&return srcS&&&&&&&&&&&&}&&&&&&&&&&&&catch (WebException we)&&&&&&&&&&&&{&&&&&&&&&&&&&&&&msg = we.M&&&&&&&&&&&&&&&&return string.E&&&&&&&&&&&&}&&&&&&&&}&&&&&&&&/// &summary&&&&&&&&&/// 从指定的 URL 下载文件到本地&&&&&&&&/// &/summary&&&&&&&&&/// &param name=&uriString&&文件 URL&/param&&&&&&&&&/// &param name=&fileName&&本地文件的完成路径&/param&&&&&&&&&/// &returns&&/returns&&&&&&&&&public bool GetFile(string urlString, string fileName, out string msg)&&&&&&&&{&&&&&&&&&&&&try&&&&&&&&&&&&{&&&&&&&&&&&&&&&&this.DownloadFile(urlString, fileName);&&&&&&&&&&&&&&&&msg = string.E&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&catch (WebException we)&&&&&&&&&&&&{&&&&&&&&&&&&&&&&msg = we.M&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&}&&&&&&&&#endregion&&&&}}原文链接:
花舞花落泪的最新日记
······
······
就是那么简单几句我办不到 · 1523条内容
博物馆讲述难以言说的历史 · 338条内容
纪念汪老逝世二十周年 · 151条内容
以赤子之心澄澈映照世界 · 106条内容
你是一本读不完的书 · 860条内容
这一天,你在干什么? · 366条内容
推荐这篇日记的豆列
······cookie值中包含等号、空格、分号等特殊字符的处理 - huangqiqing123 - ITeye技术网站
博客分类:
当cookie中包含有等号、空格、分号等特殊字符时,可能会导致数据丢失、或者不能解析的错误,一个较好的解决办法就是:在将cookie值写入客户端浏览器之前,首先进行URLEncode编码,读取cookie时,进行URLDecode即可。
提供了2种设置cookie的方法,setcookie与setrawcookie,
二者的区别是:前者会自动对cookie值进行URL编码,而后者不会进行URL编码。
php通过$_COOKIE取得客户端发送到服务器的cookie信息(不需要进行URLDecode操作)。
通过HttpServletResponse addCookie(Cookie cookie)向客户端写cookie信息;
通过HttpServletRequest
getCookies()读取cookie。
通过URLEncoder.encode(String s)对URL进行编码。
通过URLDecoder.decode(String s)对URL进行解码。
javascript
通过encodeURIComponent(URIstring)对URL进行编码
decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行解码
Server.URLEncode
Server.URLDecode
huangqiqing123
浏览: 860875 次
来自: 济南
博主这个中文版的在哪找到的?
curl请求后没有响应是什么问题呢,QQ
你好,我想我想问一下,你的二维码生成字节数组怎么做到的 Zxi ...
xiaolei1004 写道int ind = doc.add ...
int ind = doc.addPicture(byteIn ...温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(2173)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'js 设置cookie 的有效期、访问权限',
blogAbstract:'读取cookie字符串方法:alert(document.cookie); 一个网站的cookie字符串可能包含多个cookie,多个cookie之间用分号隔开,例如,包含2个cookie的字符串格式为 key1=value1;key2=value2。一个cookie字符串最长为4k,如果超过4k,将返回空值,
设置一个cookie的方法:document.cookie=\"key=expires=path=/;;secure\"
要设置多个cookie 只要反复使用&document.cookie&= XXX 即可,会自动和其他cookie拼接成一个cookie字符串。',
blogTag:'js,cookie,document.cookie',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:6,
publishTime:8,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}12560人阅读
WINDOWS驱动设计(3)
编译VC工程时出现了标题所示问题,资料搜索一下,在微软网站找到答案了,解决方法如下:1)选择&项目&-》&属性&-》&C/C++&-》&代码生成&-》&缓冲区安全检查&,设为&否&2)选择&项目&-》&属性&-》&链接器&-》&输入&-》&附加依赖项&,增加&bufferoverflowU.lib&然后编译工程,解决问题。下面是微软的原文,说的很冗长,但是很直接!
在 Windows Server 2003 Service Pack 1 通过 Win 32 软件开发工具包 (SDK) 或 Windows Server 2003 Driver Development Kit (DDK) 生成源代码时可能会收到 & 链接器工具错误 LNK 2001 & 错误信息
生成 32 位源代码或 64 位代码源代码在编译时或在链接时,您可能收到以下错误信息之一: 错误 1
链接器工具错误 LNK 2001 无法解析外部符号 __security_cookie ' '
链接器工具错误 LNK 2001
无法解析外部符号 __security_check_cookie ' '
您以生成代码, 在 Windows Server 2003 Service Pack 1 使用或者 Microsoft Win 32 软件开发工具包 (SDK) 对于 Microsoft Windows Server 2003 Service Pack 1 或 Microsoft Windows Server 2003 Driver Development Kit (DDK)。
在 Microsoft Visual Studio 2002, 新编译器开关名为 & / GS & 被引入到 Microsoft Visual C++ 编译器。 当设置 &/ GS& 开关,编译器插入编译代码中缓冲区超限检测代码。
编译器函数, 编译器可能受到缓冲区溢出,在栈上插入安全 Cookie 之前返回地址。 安全 Cookie 是计算一个模块加载时间。 在函数上安全 Cookie 值被推到堆栈。 函数退出, 上编译器 Helper 调用来确保的 Cookie 值是仍相同。 如果值更改, 这视为如符号是缓冲区溢出堆栈损坏中。 因此, 您可以检测某些直接缓冲区溢出返回地址中。
即使 / GS 开关已得到显著改进和 Visual Studio 2005, Visual Studio 2003 中 / GS 开关保护用户代码免受所有可能缓冲区溢出安全攻击 ,但是/ GS 开关并不有助于防止用户代码从所有可能缓冲区溢出安全攻击。 因小性能影响通过 / GS 开关, 新版本的 VisualC++ 编译器自动设置 / GS 切换 & & & &。 当 / GS 开关设置, 应用程序接收缓冲区溢出增强保护在运行时 & &。 这可能大大减少该应用程序是容易受到攻击。
默认情况下, 设置 VisualC++ 编译器所附带 Platform SDK 用于 Windows Server 2003 Service Pack 1 / GS 开关 & &。 源代码编译时编译器引入函数上堆栈上安全 Cookie, 插入引用到代码。 然后, 函数退出上检查是安全 Cookie 值。 此外, PlatformSDK 中的大多数库已生成与 / GS 开关设置 & &。 库已引用是以提供所需程序代码 / GS 切换增强保护运行时 & &。
VisualStudio, 用于代码中 / GS 开关位于 C 运行时库 & &。 这是由链接器, 请求中默认库。 但是, 版本所附带 PlatformSDK C 运行时库有关 VisualStudio 没有相同代码作为 C 运行时库。 发生用户构建应用程序和服务可针对不同模式是操作系统此差异是因为允许 PlatformSDK。 对安全 Cookie 添加到编译代码验证不得不以不同方式执行。 不同方式取决于什么操作系统模式服务或应用程序中运行。 它因此, 已决定来提供三库实现安全 Cookie 的验证。
bufferoverflowU.lib
此库实现功能用于安全 Cookie 验证一起使用以用户模式和在使用 Win32API 应用程序。 大多数应用程序链接到此库。
bufferoverflowK.lib
此库实现对工作安全 Cookie 检查是操作系统内核模式中。 服务和子系统在内核模式运行一定要链接到此库。
bufferoverflow.lib
该库在用户模式实现安全 Cookie 验证一起使用的功能。 由于 bufferoverflow.lib 在服务和应用不使用 Win32API 中可用但是, bufferoverflow.lib 与不同在 bufferoverflowU.lib。
要解决错误是由链接器, 引发您需要通过之一以前提到 bufferoverflow*.lib 库链接项目。 例如, 下列程序是一个简单程序, 可通过使用平台 SDK 生成。
#include &stdio.h&#include &string.h&void mymethod(char* szIn) {
char szBuf[10];
strcpy(szBuf, szIn);
puts(szBuf);}int main(int argc, char* argv[]) {
if(argc&1)
mymethod(argv[1]);}
以下代码示例显示正确编写代码要求对缓冲区溢出增强保护。 VisualC++ 编译器向编译代码添加增强保护。 无法编译代码链接因为链接器无法解析对下列引用:
__security_cookie
__security_check_cookie
&cl a.cppMicrosoft (R) C/C++ Optimizing Compiler Version 14.00.40310.32 for AMD64Copyright (C) Microsoft Corporation.
All rights reserved.a.cppMicrosoft (R) Incremental Linker Version 8.00.40310.31Copyright (C) Microsoft Corporation.
All rights reserved./out:a.exea.obja.obj : error LNK2019: unresolved external symbol __security_cookie referenced in function &void __cdecl mymethod(char *)& (?mymethod@@YAXPEAD@Z)a.obj : error LNK2019: unresolved external symbol __security_check_cookie referenced in function &void __cdecl mymethod(char *)& (?mymethod@@YAXPEAD@Z)a.exe : fatal error LNK1120: 2 unresolved externals
要解决这些错误, 您需要指定链接器必须也使用 bufferoverflowU.lib。 这假定应用程序面向用户模式, 可使用 Win32API。
&cl a.cpp bufferoverflowU.libMicrosoft (R) C/C++ Optimizing Compiler Version 14.00.40310.32 for AMD64Copyright (C) Microsoft Corporation.
All rights reserved.a.cppMicrosoft (R) Incremental Linker Version 8.00.40310.31Copyright (C) Microsoft Corporation.
All rights reserved./out:a.exea.objbufferoverflowU.lib&
如果您使用两步生成过程, 应用以下代码示例。
&cl &c a.cpp bufferoverflowU.libMicrosoft (R) C/C++ Optimizing Compiler Version 14.00.40310.32 for AMD64Copyright (C) Microsoft Corporation.
All rights reserved.a.cpp&link a.obj bufferoverflowU.libMicrosoft (R) Incremental Linker Version 8.00.40310.31Copyright (C) Microsoft Corporation.
All rights reserved.&
Microsoft 已确认这是 & 适用于 & 一节中列出 Microsoft 产品中存在问题。
有关: / GS 缓冲区安全检查在 VisualC++ 编译器选项, 请访问以下 Microsoft Developer Network (MSDN) Web 站点 & &
(/en-us/library/8dbf701c(vs.71).aspx)
有关编译器安全检查, 请访问以下 MSDN 网站:
(/en-us/library/aa290051(VS.71).aspx)
这篇文章中的信息适用于:
Microsoft Platform Software Development Kit-January 2000 Edition&当用于
Microsoft Windows Server 2003 Service Pack 1
Microsoft Windows Server 2003 Driver Development Kit&当用于
Microsoft Windows Server 2003 Service Pack 1
kbtshoot kbprb KB894573 KbMtzh kbmt
&&相关文章推荐
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:52068次
排名:千里之外
转载:16篇
(1)(1)(2)(1)(5)(1)(3)(3)(2)(7)}

我要回帖

更多关于 包含符号 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信