0

How can i make a get request with returned cookie from server ?

i am coding like this but still not working

       static void Main(string[] args)
    {
        CookieContainer container = new CookieContainer();

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://example.com");
        request.AllowAutoRedirect = true;
        request.CookieContainer = container;
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        var urlc = "https://example.com/secondUrl";

        HttpWebRequest requestca = (HttpWebRequest)WebRequest.Create(urlc);
        requestca.AllowAutoRedirect = true;
        requestca.CookieContainer = container;
        HttpWebResponse responseca = (HttpWebResponse)requestca.GetResponse();

        var aca = StreamConvert(responseca);

        File.WriteAllText("test.html", aca.ToString());

    }
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
  • 1
    From the looks of it, you are using an empty container in both calls. You should get the cookie Container from response and add that to your second call. [HttpWebResponse CookieCollection](https://learn.microsoft.com/en-us/dotnet/api/system.net.httpwebresponse.cookies?view=net-5.0) – Jawad Nov 21 '20 at 06:12
  • Hi, thank you I found Solution. i am using same cookicontainer that mean i am using same cookie , the problem was in the way how i saved File . i got Solutions thank you man : https://stackoverflow.com/questions/15712872/download-animated-gif – Mohamed Azzouz Kada Nov 23 '20 at 22:59

0 Answers0