简体   繁体   中英

Get JSESSIONID from HttpWebResponse in C# desktop application

I've created this sample using MSDN examples.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(redirUri);
request.Method = "GET";
request.CookieContainer = new CookieContainer();
Trace.WriteLine("Created request to " + redirUri);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

// Right here I want to get JSESSIONID, but Cookies are empty

foreach (Cookie cook in response.Cookies)
{
   Debug.WriteLine("{0} = {1}", cook.Name, cook.Value);
}

Cannot get JSESSIONID. I need to make several GET/POST queries in one session, that's why I need JSESSIONID. Help me please.

string cookieHeaderValue = ((System.Net.HttpWebResponse)response).Headers["Set-Cookie"].Split(new char[]{';'})[0].Trim();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM