Getting the JSESSIONID from the response Headers in C#

Posted by acadia on Stack Overflow See other posts from Stack Overflow or by acadia
Published on 2010-06-03T16:21:53Z Indexed on 2010/06/03 16:24 UTC
Read the original article Hit count: 1922

Filed under:

Hello, In my C# Windows application I am building a web request and getting the response back

Uri uri = null;
        string workplaceURL = "http://filenet:9081/WorkPlaceXT";
        uri = new Uri(workplaceURL + "/setCredentials?op=getUserToken&userId=" + encodeLabel(userName) + "&password=" + encodeLabel(pwd) + "&verify=true");
        System.Net.WebRequest webRequest = System.Net.WebRequest.Create(uri);

        System.Net.WebResponse webResponse = webRequest.GetResponse();
        StreamReader streamReader = new StreamReader(webResponse.GetResponseStream());

and I am getting the headers back as shown below

?webResponse.Headers 
{ResultXml: <?xml version="1.0"?><response><errorcode>0</errorcode><description>Success.</description></response>
Content-Language: en-US
Content-Length: 201
Cache-Control: no-cache="set-cookie, set-cookie2"
Date: Thu, 03 Jun 2010 16:10:12 GMT
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Set-Cookie: JSESSIONID=0000GiPPR9PPceZSv6d0FC4-vcT:-1; Path=/
Server: WebSphere Application Server/6.1

}
    base {System.Collections.Specialized.NameValueCollection}: {ResultXml: <?xml version="1.0"?><response><errorcode>0</errorcode><description>Success.</description></response>
Content-Language: en-US
Content-Length: 201
Cache-Control: no-cache="set-cookie, set-cookie2"
Date: Thu, 03 Jun 2010 16:10:12 GMT
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Set-Cookie: JSESSIONID=0000GiPPR9PPceZSv6d0FC4-vcT:-1; Path=/
Server: WebSphere Application Server/6.1

How do I fetch just the JSESSIONID? as I need to pass the JSESSIOID to a different URL. Please help

© Stack Overflow or respective owner

Related posts about c#