[C#HttpHelper]2013-11-21关于Cookie的重要更新
导读部分
-------------------------------------------------------------------------------------------------------------
C#HttpHelper类苏飞版--系列教程导航
http://www.sufeinet.com/thread-3-1-1.html
|
因为@qq33444610的反馈对Cookie的设置进行的修复原方法[C#] 纯文本查看 复制代码 private void SetCookie(HttpItem item)
{
if (!string.IsNullOrWhiteSpace(item.Cookie))
//Cookie
request.Headers[HttpRequestHeader.Cookie] = item.Cookie;
//设置Cookie
if (item.ResultCookieType == ResultCookieType.CookieCollection && item.CookieCollection != null && item.CookieCollection.Count > 0)
{
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(item.CookieCollection);
}
}
修改后方法
[C#] 纯文本查看 复制代码 /// <summary>
/// 设置Cookie
/// </summary>
/// <param name="item">Http参数</param>
private void SetCookie(HttpItem item)
{
//Cookie
if (!string.IsNullOrEmpty(item.Cookie))
{
request.Headers[HttpRequestHeader.Cookie] = item.Cookie;
}
if (item.ResultCookieType == ResultCookieType.CookieCollection)
{
request.CookieContainer = new CookieContainer();
}
//设置CookieCollection
if (item.CookieCollection != null && item.CookieCollection.Count > 0)
{
request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(item.CookieCollection);
}
}
请大家及时更新,
原方法有Bug,只设置ResultCookieType == ResultCookieType.CookieCollection是不会返回CookieCollection的,只有设置一个值才行,经修改后这个问题已修复。请大家赶紧下载使用吧下载地址http://www.sufeinet.com/thread-3-1-1.html
|