-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCookieManager.cs
executable file
·72 lines (61 loc) · 2.52 KB
/
CookieManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Net;
namespace consolestatisticsappcsharp
{
public class CookieManager
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static CookieContainer cookies = new CookieContainer();
public static CookieContainer Cookies
{
get
{
return cookies;
}
}
public static void AddCookie(Cookie cookie)
{
//log.Debug("\n>>>>Storing Cookie to CookieManager>>>>: \n" +
//" Domain: " + cookie.Domain + "\n" +
//" Path: " + cookie.Path + "\n" +
//" Expires: " + cookie.Expires.ToUniversalTime() + "\n" +
//" Name: " + cookie.Name + "\n" +
//" Value: " + cookie.Value + "\n");
cookies.Add(cookie);
}
public static void SaveCookies(Uri uri, IDictionary<string, string> headers)
{
foreach (string key in headers.Keys)
{
if (key.ToUpper().Equals("SET-COOKIE"))
{
string cookieValue = headers[key];
CookieManager.AddCookies(uri, cookieValue);
}
}
}
public static void AddCookies(Uri uri, string cookieHeader)
{
cookies.SetCookies(uri, cookieHeader);
}
public static CookieCollection GetCookieCollection(Uri uri)
{
return cookies.GetCookies(uri);
}
public static void DumpCookies(String baseUrl)
{
CookieCollection cookieCollection = cookies.GetCookies(new Uri(baseUrl + "/statistics/v3"));
log.Debug("\nCookies for " + baseUrl + ": " + cookies.Count);
foreach (Cookie cookie in cookieCollection)
{
log.Debug("\n<<<<Cookie from CookieContainer<<<<: \n" +
" Domain: " + cookie.Domain + "\n" +
" Path: " + cookie.Path + "\n" +
" Expires: " + cookie.Expires.ToUniversalTime() + "\n" +
" Name: " + cookie.Name + "\n" +
" Value: " + cookie.Value + "\n");log.Debug(cookie.Name + ": " + cookie.Value);
}
}
}
}