Here is a sample code if anyone is interested.
class Program
{
static void Main(string[] args)
{
CookieContainer session = new CookieContainer();
HttpWebRequest httpSomeRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8080/someURL");
httpSomeRequest.CookieContainer = session;
httpSomeRequest.GetResponse();
HttpWebRequest httpSomeOtherRequest = (HttpWebRequest)WebRequest.Create("http://localhost:8080/someOtherURL");
httpSomeOtherRequest.CookieContainer = session;
httpSomeOtherRequest.GetResponse();
}
}
We just need to make sure that every created one HttpWebRequestuses the same instance CookieContainer.
source
share