mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 21:21:34 +00:00
57 lines
1.3 KiB
C#
57 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace DotNet.Utilities
|
|
{
|
|
public static class HttpCookieHelper
|
|
{
|
|
public static List<CookieItem> GetCookieList(string cookie)
|
|
{
|
|
List<CookieItem> list = new List<CookieItem>();
|
|
string[] array = cookie.Split(new string[2] { ";", "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
foreach (string input in array)
|
|
{
|
|
if (Regex.IsMatch(input, "([\\s\\S]*?)=([\\s\\S]*?)$"))
|
|
{
|
|
Match match = Regex.Match(input, "([\\s\\S]*?)=([\\s\\S]*?)$");
|
|
list.Add(new CookieItem
|
|
{
|
|
Key = match.Groups[1].Value.Trim(),
|
|
Value = match.Groups[2].Value.Trim()
|
|
});
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public static string CookieFormatByReustCookie(string cookie)
|
|
{
|
|
GetCookieList(cookie);
|
|
string text = "";
|
|
foreach (CookieItem cookie2 in GetCookieList(cookie))
|
|
{
|
|
text += CookieFormat(cookie2.Key, cookie2.Value);
|
|
}
|
|
return text;
|
|
}
|
|
|
|
public static string GetCookieValue(string Key, string cookie)
|
|
{
|
|
foreach (CookieItem cookie2 in GetCookieList(cookie))
|
|
{
|
|
if (cookie2.Key == Key)
|
|
{
|
|
return cookie2.Value;
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public static string CookieFormat(string key, string value)
|
|
{
|
|
return $"{key}={value};";
|
|
}
|
|
}
|
|
}
|