asp .net obtain information from the Header

///


// get header information
///

///
Private void the GetHeader (HttpResponseMessage Response)
{
. = Response.Headers.ToString headers var () Split (new new [] { '\ n-', '\ R & lt'}, StringSplitOptions.RemoveEmptyEntries);
the Dictionary <String, String> the Dictionary = new new Dictionary <String, String> ();
the foreach (var header in headers)
{
// must be split in two predetermined, otherwise data will be lost Set-Cookie
string [] splitStr = header.Split (new char [] { ':'}, 2);
var name = splitStr [0];
var value = splitStr [. 1] .trim ();
dictionary.Add (name, value);
}
// HeaderData custom class objects, header information is stored
= new new HeaderData headerData ();
var Dictionary cookiePairs = [ "the Set-cookies"];
headerData.YourKeyword = GetValueByRegex(cookiePairs, "your keyword");
}

private static string GetValueByRegex(string cookieStr, string pattern)
{
Regex regex = new Regex($"{pattern}=(\S+);");
Match match = regex.Match(cookieStr);
var pair = match.Groups[0].Value;
pair = pair.TrimEnd(';');
string[] keyAndValue = pair.Split('=');
string value = keyAndValue[1];
return value;
}

Guess you like

Origin www.cnblogs.com/Lulus/p/12602903.html