0

I create a new HTTPWebRequest, but I am unable to assign a CookieContainer to it, how would this be possible?

CookieContainer = new CookieContainer();

//Create a WebRequest to get the file
HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(@"http://www.example.com/file.zip);
James Teare
  • 372
  • 1
  • 12
  • 23

1 Answers1

3

Here is a simple example of using CookieContainer

       public static void Main(string[] args)
        {   
            if (args == null || args.Length != 1)
            {
                Console.WriteLine("Specify the URL to receive the request.");
                Environment.Exit(1);
            }
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(args[0]);
            request.CookieContainer = new CookieContainer();

            HttpWebResponse response = (HttpWebResponse) request.GetResponse();



            // Print the properties of each cookie.
            foreach (Cookie cook in response.Cookies)
            {                    
                // Show the string representation of the cookie.
                Console.WriteLine ("String: {0}", cook.ToString());
            }
        }
Sandeep Singh Rawat
  • 1,637
  • 1
  • 14
  • 27