2
using (HttpWebResponse httpWebResponse = (HttpWebResponse)templateRequest.GetResponse())
{
    using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
    {
        header = httpWebResponse.Cookies;

That is my response's cookies but here is my request

HttpWebRequest templateRequest = base.GetTemplateRequest("https://apps.runescape.com/runemetrics/profile/profile?activities=20");

templateRequest.CookieContainer = ???????????

Now how do I take my cookies from the response to the request?

I've tried

CookieContainer cookies = new CookieContainer();

foreach(Cookie cookie in header)
{
    cookies.Add(cookie);
}
templateRequest.CookieContainer = cookies;

but it didn't work :(

GSerg
  • 76,472
  • 17
  • 159
  • 346
  • 2
    Possible duplicate of [how to use cookies with HttpWebRequest](https://stackoverflow.com/questions/2972643/how-to-use-cookies-with-httpwebrequest) – GSerg May 01 '18 at 15:23
  • @GSerg Nono because the httpwebresponse doesn't return a cookiecontainter :( – refactorcoding May 01 '18 at 15:25
  • 1
    No, but the request object takes one and stores the resulting cookies in the container. The accepted answer on the question GSerg linked to demonstrates as much. – ProgrammingLlama May 01 '18 at 15:38
  • And yes, it does seem like bad design on Microsoft's part, but that's the way it is. – ProgrammingLlama May 01 '18 at 15:40
  • The method linked by GSerg is the good one in this context (WebRequest). Discard methods that try to add Cookies in other, extravagant, ways. The CookieContainer can be stored and re-assigned to a WebRequest when needed. – Jimi May 01 '18 at 17:08

0 Answers0