1

how to change the value or add a new cookie to an existing cookie? For example, I use a simple code as below :

    Uri site = new Uri(https://example.com);
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(site);
    CookieContainer cookieContainer = new CookieContainer();
    request.CookieContainer = cookieContainer;

    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    {
        var myCookie = cookieContainer.GetCookieHeader(site);
    }

and generate the following cookies :

Name1=Value1; Name2=Value2; Name3=Value3

supposing I want to change the value of cookie Name2 to "replaceValue2" and I want to add cookies (name4=value4). The following is an example of the results I want ...

Name1=Value1; Name2=replaceValue2; Name3=Value3; Name4=Value4
Newbie
  • 33
  • 3
  • The question about changing a value retrieved from a container/otherwise has been asked before. The summary will be that you cannot change a cookie you can only create a new one - https://stackoverflow.com/questions/22070840/change-a-cookie-value-of-a-cookie-that-already-exists – Dane Balia Dec 23 '20 at 14:24
  • @DaneBalia maybe I understand a little about adding cookies, but I'm still confused by changing the value of cookies. are there any other examples that are slightly closer to my case? – Newbie Dec 23 '20 at 14:38

0 Answers0